I am just starting out with win32 GDI programming and finding good references hard to come by. I have a simple application that captures the screen by doing the following:
UINT32 x,y;
x = GetSystemMetrics(SM_CXSCREEN);
y = GetSystemMetrics(SM_CYSCREEN);
HDC hdc = GetDC(NULL);
HDC hdcScreen = CreateCompatibleDC(hdc);
HBITMAP hbmp = CreateCompatibleBitmap(hdc, x, y);
SelectObject(hdcScreen, hbmp);
BitBlt(hdcScreen, 0, 0, x, y, hdc, 0, 0, SRCCOPY)
ReleaseDC(NULL, hdc);
I am capturing a compatible bitmap which on my machine is 32-bit. Using same/similar calls how would I capture the screen in 8-bit? What about as 16-bit?
Use CreateDIBSection to create a 8bpp bitmap, and BitBlt onto that.
Filling in the BITMAPINFO structure is going to be the interesting. You can’t use a normal BITMAPINFO struct as it only allocates space for a single palette entry and, with a 8bpp image – you will need the full 256 entries.
If you want to cheat a bit, one can use a anonymous union to declare a BITMAPINFO with enough space for its palette.
As to the values to initialize in the color table… I can’t think of an easy way to get a default 8bpp palette from GDI when its not in 8bpp mode. I have a suspicion that CreateHalftonePalette isn’t going to do anything on a non palette device.