473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Robbie
180 100+
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...
Jul 1 '07 #1
4 1713
Killer42
8,435 Expert 8TB
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.

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.  
  9. Private Sub cmdGetColours_click()
  10.     Dim fColours As Single
  11.     fColours = DeviceColors(hDC)
  12.     If fColours = 4294967296# Then
  13.         Debug.Print "Colors: " & fColours & " - True Color (32 bit)"
  14.     ElseIf fColours = 65536# Then
  15.         Debug.Print "Colors: " & fColours & " - High Color (16 bit)"
  16.     Else
  17.         Debug.Print "Colors: " & fColours
  18.     End If
  19. End Sub


(Edited by Killer42. The original code contained bugs. I'll post it in another message, for historical interest.)
Jul 2 '07 #2
Killer42
8,435 Expert 8TB
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)
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.  
  9. Private Sub cmdGetColours_click()
  10.     Dim fColours As Single
  11.     fColours = DeviceColors((hDC))
  12.     If fColours = "4.294967E+09" Then
  13.         lblColours.Caption = "Colors: " & Colours & " -True Color (32 bit)"
  14.     ElseIf fColours = "65536" Then
  15.         lblColours.Caption = "Colors: " & Colours & " - High Color (16 bit)"
  16.     Else
  17.         lblColours.Caption = "Colors: " & Colours
  18.     End If
  19. End Sub
Jul 2 '07 #3
Robbie
180 100+
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.
Jul 2 '07 #4
Killer42
8,435 Expert 8TB
Thanks very much! ^^
Works just like it should.
Glad to hear it! :)

I might add this to the Articles area.
Jul 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: John Hunter | last post by:
I have a largish data set (1000 observations x 100 floating point variables), and some of the of the data are missing. I want to try a variety of clustering, neural network, etc, algorithms on the...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
3
by: scoobydoo | last post by:
hi, I have a problem displaying icons at the right colour depthin a ListView. I've made an icon file, (using IconWorkshop 5), it has 3 icons within it. A 32x32 32bpp XP style icon, a 32x32...
0
by: Paul Cheetham | last post by:
Hi, I have several Colour custom cursors embedded in my application resource. In order to load and use them I use the following function: public static Cursor LoadCursor (string CursorName) {...
26
by: johkar | last post by:
I need to cancel the link and execute a function onclick of all the links within the span tag which has a class of "container" assigned. There will be only one span tag with this class applied. ...
5
by: Dave White | last post by:
Hello Everyone, I have not had any luck finding a tool that will: Shows me the color when I highlight a Hex color code in an HTML source document. Are there any utilities that do this? ...
2
by: kuratkull | last post by:
Hello, I haven't asked If I wasn't really confused :) OK, so I am just beginning SDL programming in C, and I was running fine, until I tried getting a pixel colour. Basically, I am trying to...
4
by: cjstuttle | last post by:
Could anyone help me, I'm a python noob and need some help. im trying to find some code that will, given a screen co-ordinate, will give me the colour of that pixel in RGB. i have found a lot about...
21
Mas Juliza Alias
by: Mas Juliza Alias | last post by:
Hi, I am building a program on Information System for Reservoir Operation for my Masters research. Now I have a text file which is an output file from a processing software (Terramodel) that lists...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.