Determine the Colour Depth

This piece of code shows you how to find out the colour depth of the screen using the GetDeviceCaps API.

Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long

Function DeviceColors(hDC As Long) As Single
    Const PLANES = 14
    Const BITSPIXEL = 12
    DeviceColors = 2 ^ (GetDeviceCaps(hDC, PLANES) * GetDeviceCaps(hDC, BITSPIXEL))
End Function

Private Sub cmdGetColours_click()
    Dim fColours As Single
    fColours = DeviceColors((hDC))
    If fColours = "4.294967E+09" Then
        lblColours.Caption = "Colors: " & Colours & " -True Color (32 bit)"
    ElseIf fColours = "65536" Then
        lblColours.Caption = "Colors: " & Colours & " - High Color (16 bit)"
    Else
        lblColours.Caption = "Colors: " & Colours
    End If
End Sub

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”