int main() { /* Allocate enough space for a DIB header plus palette (for * 8-bit modes) or bitfields (for 16- and 32-bit modes) */ int dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); LPBITMAPINFO dib = (LPBITMAPINFO) malloc(dib_size); memset(dib, 0, dib_size); dib->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); /* Get a device-dependent bitmap that's compatible with the screen. */ HDC hdc = GetDC(NULL); HBITMAP hbm = CreateCompatibleBitmap( hdc, 1, 1 ); /* Convert the DDB to a DIB. We need to call GetDIBits twice: * the first call just fills in the BITMAPINFOHEADER; the * second fills in the bitfields or palette. */ printf("getting bits 1\n"); GetDIBits(hdc, hbm, 0, 1, NULL, dib, DIB_RGB_COLORS); printf("BitCount is %d\n",dib->bmiHeader.biBitCount); if (dib->bmiHeader.biCompression == BI_BITFIELDS) { printf("BitMask is red=%08x,blue=%08x,green=%08x\n",dib->bmiColors[0].rgbRed,dib->bmiColors[0].rgbBlue,dib->bmiColors[0].rgbGreen); } GetDIBits(hdc, hbm, 0, 1, NULL, dib, DIB_RGB_COLORS); DeleteObject(hbm); ReleaseDC(NULL, hdc); printf("BitCount is %d\n",dib->bmiHeader.biBitCount); if (dib->bmiHeader.biCompression == BI_BITFIELDS) { printf("BitMask is red=%08x,blue=%08x,green=%08x\n",dib->bmiColors[0].rgbRed,dib->bmiColors[0].rgbBlue,dib->bmiColors[0].rgbGreen); } free(dib); }