Hi
I am trying to make my win32 program double buffer but it just wont display what i am drawing.
My code is:
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
GetClientRect(hwnd, &r);
if (r.bottom == 0) {
return;
}
int width = r.right - r.left;
int height = r.top - r.bottom;
// Get DC for window
hdc = BeginPaint(hwnd, &ps);
// Create an off-screen DC for double-buffering
hdcMem = CreateCompatibleDC(hdc);
hbmMem = CreateCompatibleBitmap(hdc, width, height);
hOld = SelectObject(hdcMem, hbmMem);
// Draw into hdcMem here
for (int x = 0; x < 100; x++)
for (int y = 0; y < 100; y++)
SetPixel(hdcMem, x, y, RGB(255, 0, 0));
// Transfer the off-screen DC to the screen
BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);
// Free-up the off-screen DC
SelectObject(hdcMem, hOld);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
return 0;
Any help would be greatly appreciated.
Thanks