Connecting Tech Pros Worldwide Forums | Help | Site Map

How to: Determine number of colours

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#1   Jul 3 '07
This simple function may be called to determine the colour "depth" of the display, using the GetDeviceCaps API.

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
  2.  
  3. Function DeviceColors(hDC As Long) As Single
  4.   Const PLANES = 14
  5.   Const BITSPIXEL = 12
  6.   DeviceColors = 2 ^ (GetDeviceCaps(hDC, PLANES) * GetDeviceCaps(hDC, BITSPIXEL))
  7. End Function
  8.  
To use this function, just pass it the hDC of your current form.
Some typical values returned...
4,294,967,296 = "True Color" (32 bit)
65,536 = "High Color" (16 bit)



Closed Thread


Similar Visual Basic 4 / 5 / 6 bytes