October 24, 2016
Hot Topics:

Screen Resolutions

  • November 19, 2002
  • By Steve Anderson
  • Send Email »
  • More Articles »

Now that you have know how to retrieve the screen resolution you may want to know how you can retrieve the number of colours that is available to Windows. The options are: 16 colours, 4 bit; 256 colours,8 bit; 65536 colours, 16 bit; 16.7 million colours, either 24 bit or 32 bit.


This API function is important in retrieving the number of colours that is available to windows. It returns the information on a given index. The paramters are:

Hdc – This is the handle of the device context that you find by using CreateIC.

nIndex – This is the information that you want to retrieve from the display driver. The constants that are important in this section of the article are

Constant Description
BITSPIXEL This is the number of bits that are available per pixel. This will return 4, 8, 16, 24 or 32.
PLANES This returns the number of colour planes


This API function is used to create a device context, which allows easy access to device information. This CreateIC API function has these parameters:

LpDriverName – This specifies the name of the driver that you want to retrieve information on. This is usually ‘Display’ for information on the display driver.

LpDeviceName – This should be left as null

LpOutput – This should be left as null

LpInitData – This should be left as null


This simply deletes the device context that was created by using CreateIC. You must do this for every device context that you create in order to free up Windows resources.

To retrieve the number of colours that are available to Windows we first need to find out how many planes are available to windows, which will be either 1 or 4. Most machines will support 1 plane.

This function returns the number of colours and colour depth as a string:

Private Const BITSPIXEL = 12
Private Const PLANES = 14

Private Declare Function CreateIC Lib "gdi32" _
Alias "CreateICA" (ByVal lpDriverName As String, _
ByVal lpDeviceName As Any, ByVal lpOutput As Any, _
ByVal lpInitData As Any) As Long

Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long

Private Declare Function DeleteDC Lib "gdi32" _
(ByVal hdc As Long) As Long

Public Function GetAvailableColours() As String
Dim lHdc As Long, lPlanes As Long, lBitsPerPixel As Integer
' Declare variables
lHdc = CreateIC("DISPLAY", 0&, 0&, 0&)
' Create the device context for the display
If lHdc = 0 Then
  ' An error has occurred and the function will exit
  GetAvailableColours = "Error"
Exit Function
End If

lPlanes = GetDeviceCaps(lHdc, PLANES)
' Return info on number of planes

lBitsPerPixel = GetDeviceCaps(lHdc, BITSPIXEL)
' Use display device 
' context to return info on the
' number of pixels

lHdc = DeleteDC(lHdc)
' Delete the device context

Select Case lPlanes

Case 1

' 1 plane is available. This 
' will be the same for most
' computer systems

Select Case lBitsPerPixel
' Select the number of colours available
Case 4: GetAvailableColours = _
"4 Bit, 16 Colours"
Case 8: GetAvailableColours = _
"8 Bit, 256 Colours"
Case 16: GetAvailableColours = _
"16 Bit, 65536 Colours"
Case 24: GetAvailableColours = _
"24 Bit True Colour, 16.7 Million Colours"
Case 32: GetAvailableColours = _
"32 Bit True Colour, 16.7 Million Colours"
End Select

Case 4
GetAvailableColours = "16 Bit, 65536 Colours"
' If there are 4 planes then the availible
' colours will be 16-bit
Case Else

GetAvailableColours = "Undetermined"
' The number of colours could not bee determined

End Select

End Function

The functions here are demonstrated in the GetColourDepth demo project.

Page 3 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel