I am trying to build a very simple graphical app using C++, windows api and GDI+. When first trying to build the app, heavy flickering was introduced, so this code tries to use double buffering, but fails. hdcBuf is the backbuffer.
When trying to draw something to the backbuffer using GDI+ Graphics::DrawCachedBitmap the bitmap is drawn dual-colored in black and white.
LoadBitmapRes creates a CachedBitmap from the EXE resources; this function works with single buffering.
Is there anything wrong in the code? Thanks in advance!
Global:
CachedBitmap* fish;
HDC hdc;
HDC hdcBuf;
HBITMAP hbmpBuf;
Graphics* gfxBuf;
WM_CREATE:
hdc = GetDC(hwnd);
hdcBuf = CreateCompatibleDC(hdc);
hbmpBuf = CreateCompatibleBitmap(hdcBuf, 640, 480);
SelectObject(hdcBuf, hbmpBuf);
gfxBuf = Graphics::FromHDC(hdcBuf);
fish = LoadBitmapRes(gfxBuf, MAKEINTRESOURCE(FISH2), "SPRITE");
WM_PAINT:
HDC temp = BeginPaint(hwnd, &ps);
gfxBuf->DrawCachedBitmap(fish, x, y);
BitBlt(temp, 0, 0, 640, 480, hdcBuf, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);