Y'all are not gonna believe this! After three days of scouring the internet, and pulling my hair out, I stumbled across the solution by pure accident---all, from a mistyped line of code. The solution proved to be so simple and obvious, that it was ridiculous. Without going into long details of how I made my accidental discovery, here is what I found:
Using GDIPlus, I had loaded a JPEG image into memory. In WM_PAINT, I used this code to display the image:
|
graphic1.DrawImage(image1, Key->xImgOrg, Key->yImgOrg, cxSize, cySize);
|
I decided to draw a line on the image, just to see what would happen. For the line, I used the standard GDI functions, rather than GDIPlus. Here is how that bit of code looked now:
1 2 3 4 5 6
|
graphic1.DrawImage(image1, xImgOrg, yImgOrg, cxSize, cySize);
SelectObject(hdc, GetStockObject(DC_PEN)); // Test Line
SetDCPenColor(hdc, RGB(255, 0, 0));
MoveToEx(hdc, xImgOrg+100, yImgOrg+100, NULL);
LineTo(hdc, xImgOrg+1100, yImgOrg+1100);
|
The line was drawn, just as I wanted. It even scrolled with the image. I then had WM_PAINT draw the image again, over the line. This is how that bit of code looked now:
1 2 3 4 5 6 7 8
|
graphic1.DrawImage(image1, xImgOrg, yImgOrg, cxSize, cySize);
SelectObject(hdc, GetStockObject(DC_PEN)); // Test Line
SetDCPenColor(hdc, RGB(255, 0, 0));
MoveToEx(hdc, xImgOrg+100, yImgOrg+100, NULL);
LineTo(hdc, xImgOrg+1100, yImgOrg+1100);
graphic1.DrawImage(image1, xImgOrg, yImgOrg, cxSize, cySize);
|
The line was erased! It would appear, that GDIPlus double-buffers images by default. No wonder my attempts at double-buffering were producing such erratic and crazy results. I was fighting something that was already there.
I did some experimentation, to see how practical this little trick might be. With a little code tweaking, I found that "InvalidateRect()" could also be used to erase all or part of the line---as well as redraw it in a new location. The only tricky part came in defining the coordinates. The drawing functions use the Image coordinates, while "InvalidateRect()" uses the coordinates of the window.
Anyway, that's my story.