I haven't written anything with GDI for a while now (and never with GDI+), and I'm just working on a fun project, but for the life of me, I can't figure out how to double buffer GDI+
void DrawStuff(HWND hWnd) {
HDC hdc;
HDC hdcBuffer;
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
hdcBuffer = CreateCompatibleDC(hdc);
Graphics graphics(hdc);
graphics.Clear(Color::Black);
// drawing stuff, i.e. bunnies:
Image bunny(L"bunny.gif");
graphics.DrawImage(&bunny, 0, 0, bunny.GetWidth(), bunny.GetHeight());
BitBlt(hdc, 0,0, WIDTH , HEIGHT, hdcBuffer, 0,0, SRCCOPY);
EndPaint(hWnd, &ps);
}
The above works (everything renders perfectly), but it flickers. If I change Graphics graphics(hdc); to Graphics graphics(hdcBuffer);, I see nothing (although I should be bitblt'ing the buffer-hWnd hdc at the bottom).
My message pipeline is set up properly (WM_PAINT calls DrawStuff), and I'm forcing a WM_PAINT message every program loop by calling RedrawWindow(window, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW);
I'm probably going about the wrong way to do this, any ideas? The MSDN documentation is cryptic at best.