Getting the display bitcount (i.e. 'colour depth')

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robbie
    New Member
    • Mar 2007
    • 180

    Getting the display bitcount (i.e. 'colour depth')

    Hi again, does anybody know how to get the number of colours / colour depth which the display is set to use, in Visual Basic 6?
    (i.e. 8-bit, 16-bit or 32-bit)

    I know how to find out the horizontal/vertical resolution, but it's the depth I need...
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by Robbie
    Hi again, does anybody know how to get the number of colours / colour depth which the display is set to use, in Visual Basic 6?
    (i.e. 8-bit, 16-bit or 32-bit)

    I know how to find out the horizontal/vertical resolution, but it's the depth I need...
    Sourced from another forum...

    Author: James Crowley

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

    [CODE=vb]Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long

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

    Private Sub cmdGetColours_c lick()
    Dim fColours As Single
    fColours = DeviceColors(hD C)
    If fColours = 4294967296# Then
    Debug.Print "Colors: " & fColours & " - True Color (32 bit)"
    ElseIf fColours = 65536# Then
    Debug.Print "Colors: " & fColours & " - High Color (16 bit)"
    Else
    Debug.Print "Colors: " & fColours
    End If
    End Sub[/CODE]


    (Edited by Killer42. The original code contained bugs. I'll post it in another message, for historical interest.)

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Just in case anyone is interested, here is the original code, before I edited it.

      Warning: This code contains at least one serious bug (in the test code, not the actual function)[CODE=vb]Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, ByVal nIndex As Long) As Long

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

      Private Sub cmdGetColours_c lick()
      Dim fColours As Single
      fColours = DeviceColors((h DC))
      If fColours = "4.294967E+ 09" Then
      lblColours.Capt ion = "Colors: " & Colours & " -True Color (32 bit)"
      ElseIf fColours = "65536" Then
      lblColours.Capt ion = "Colors: " & Colours & " - High Color (16 bit)"
      Else
      lblColours.Capt ion = "Colors: " & Colours
      End If
      End Sub[/CODE]

      Comment

      • Robbie
        New Member
        • Mar 2007
        • 180

        #4
        Originally posted by Killer42
        Sourced from another forum...

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

        ...

        (Edited by Killer42. The original code contained bugs. I'll post it in another message, for historical interest.)
        Thanks very much! ^^
        Works just like it should.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by Robbie
          Thanks very much! ^^
          Works just like it should.
          Glad to hear it! :)

          I might add this to the Articles area.

          Comment

          Working...