Microsoft KB Archive/139202

{|
 * width="100%"|

HOWTO: Detect the Number of Colors Available in a DC

 * }

Q139202

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK) 3.1
 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows NT Server versions 3.5, 3.51
 * Microsoft Windows NT Workstation versions 3.5, 3.51
 * Microsoft Windows 4.0
 * Microsoft Windows 95
 * Microsoft Win32s versions 1.2, 1.25a, 1.3
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

-

SUMMARY
When writing an application that uses the GDI, you may sometimes need to detect how many colors are available in the current video mode.

MORE INFORMATION
If you need to detect the total number of bits that are used to form a pixel in a given display context, you can use the following algorithm:

int dBitsInAPixel = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);

To determine how many colors are available, you can raise 2 to the power of dBitsInAPixel and this will return the maximum number of colors that are displayable at a given time in the specified display context (DC).

Additional query words: 1.20 3.10 4.00 3.50 colorref rgb bpp

Keywords : kbOSWin2000

Issue type : kbhowto

Technology : kbAudDeveloper kbSDKSearch kbWin32sSearch kbWin32API kbWinSDKSearch