When creating a memory DC using CreateCompatibleDC
its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Consequently when calling CreateCompatibleBitmap
on this memory DC a monochrome bitmap is created.
Since the bitmap selected into a memory DC controls the color characteristics, you have to make sure that it matches the DC you are eventually using to display the contents of the memory DC. To do so you should pass the destination DC to CreateCompatibleBitmap
.
Corrected code:
hdc = GetDC(hwnd);
hdcBuf = CreateCompatibleDC(hdc);
hbmpBuf = CreateCompatibleBitmap(hdc, 640, 480); // uses source DC
SelectObject(hdcBuf, hbmpBuf);