Home | Articles | Links | Contact
 
Title Get the color depth in bits per pixel of the current Windows display
Description We're back to Windows API to get the color depth of the current Windows display. Color depth will be retrieved in bits per pixel, 8 bits per pixel means 256 colors, 16 bits per pixel is what Windows calls high density color, etc.
Date 10/11/2000
Last revision

Sometimes you may need to find out how many colors you can use in your application. Windows API is again here to tell us. There is a function called GetDeviceCaps that can provide information about the capabilities of any given display device in Windows, such as the screen or a printer. This function needs two parameters, the first one is the HDC (device-context handle) of the device you want to retrieve information from, the second one is an index to the kind of information you want to retrieve. Windows API defines several constants to use as indexes for the second parameter such as DRIVERVERSION, HORZRES, VERTRES and, of course, BITSPIXEL. We can just provide the function with the HDC of the desktop window, as we can find in the help file "Win32 Developer's References":

"The desktop window covers the entire screen. The desktop window is the area on top of which all icons and other windows are painted."

Good enough for us right now. We have now all the elements we need, the call to GetDeviceCaps will be:

bitsPerPixel := GetDeviceCaps( GetDc( GetDesktopWindow), BITSPIXEL);

Was this article useful for you?
Yes No
Any other comments will be welcome

Home | Articles | Links | Contact