Originally Posted by
novacain
Create a DC compatible to the screen (CreateCompatibleDC)
Create a bitmap compatible to the screen (CreateCompatibleBitmap) .
SelectObject the bitmap into the memDC, saving the default bmp that is 'pushed' out.
Clean up any GDI objects (ie release any GetDC()'s).
Okay, borrowing from older posts, I have recreated the code I need.
Code:
HdcWindow = BeginPaint(hwnd, &ps);
HdcBuffer = CreateCompatibleDC(HdcWindow);
DoubleBuffer = CreateCompatibleBitmap(HdcWindow, MYWIDTH, MYHEIGHT);
OldBuffer = (HBITMAP)SelectObject(HdcBuffer, DoubleBuffer);
FillRect(HdcBuffer, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
HdcBitmap = CreateCompatibleDC(HdcWindow);
For the most part it seems to be working.
I have added this to WM_PAINT:
Code:
case WM_PAINT:
BitBlt(HdcWindow, 0, 0, MYWIDTH, MYHEIGHT, HdcBuffer, 0, 0, SRCCOPY);
break;
the only problem is, that, for some reason WM_PAINT goes into an endless loop.
I found that if I add this:
Code:
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
BitBlt(HdcWindow, 0, 0, MYWIDTH, MYHEIGHT, HdcBuffer, 0, 0, SRCCOPY);
break;
it works just fine. I don't get it...
Draw the changes to the memDC
Call for a paint msg (InvalidateRect() followed by UpdateWindow() )
Well, when the only thing I draw to my buffer is a line, like this:
Code:
void DrawLine(HWND hwnd)
{
HDC myhDC = HdcBuffer;
int x = 50, y = 50;
MoveToEx(myhDC, x, y, NULL);
LineTo(myhDC, x + 100, y);
InvalidateRect(hwnd, &glrect, FALSE);
UpdateWindow(hwnd);
}
this alone does not seem to work.
However, if I add a BitBlt() at the end, like this:
Code:
InvalidateRect(hwnd, &glrect, FALSE);
UpdateWindow(hwnd);
BitBlt(HdcWindow, 0, 0, MYWIDTH, MYHEIGHT, myhDC, 0, 0, SRCCOPY);
}
then it works.
Of course, I'm forceing it to work. I can live with this.
What I think I need to fix, though, is the WM_PAINT thing.
Any suggestions ?