/* vidfmt.c: Check video display format */ #include #include int main(int argc, char* argv[]) { int dib_size; LPBITMAPINFOHEADER dib_hdr; HDC hdc; HBITMAP hbm; /* Allocate enough space for a DIB header plus palette (for * 8-bit modes) or bitfields (for 16- and 32-bit modes) */ dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); dib_hdr = (LPBITMAPINFOHEADER) malloc(dib_size); memset(dib_hdr, 0, dib_size); dib_hdr->biSize = sizeof(BITMAPINFOHEADER); /* Get a device-dependent bitmap that's compatible with the screen. */ hdc = GetDC(NULL); 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. */ GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); DeleteObject(hbm); ReleaseDC(NULL, hdc); printf("Current video mode is %lu-bit.\n", dib_hdr->biBitCount); if (BI_BITFIELDS == dib_hdr->biCompression) { DWORD * fields = (DWORD*) ((char*)dib_hdr + dib_hdr->biSize); switch (fields[0]) { case 0xf800: printf(" (565 BGR pixel alignment)\n"); break; case 0x7c00: printf(" (555 BGR pixel alignment)\n"); break; case 0xff0000: printf(" (888 BGR pixel alignment)\n"); break; case 0x0000ff: printf(" (888 RGB pixel alignment)\n"); break; default: printf(" (Unknown pixel alignment %x:%x:%x)\n", fields[0], fields[1], fields[2] ); } } free(dib_hdr); return 0; }