
how can I retrieve the number of colors/bits per pixel used/avaliable by the system
Quote:
> > Passing 0 to GetDC implies the desktop/screen, so it can be simplified
> > a bit by eliminating the GetDesktopWindow call...
> Again I find my method more immediately understandable and readable since
> it's evident we've querying the desktop window's DC for it's bit-depth,
but
> it's up to the programmer I guess.
For completeness, here is the VBnet version (Randy Birch's site). Which
avoids the first API call altogether and just passes in hdc (which implies
me.hdc).
http://www.mvps.org/vbnet/index.html?code/screen/displaysettings.htm
This made me curious so I wrote a small test. Just paste this in to a form
and you can see the results in the immediate window when the form loads:
'************
Option Explicit
Private Declare Function GetDesktopWindow Lib "User32" () As Long
Private Declare Function GetDC Lib "User32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "User32" (ByVal hWnd As Long, ByVal
hDC As Long) As Long
Private Sub Form_Load()
Debug.Print "me hdc =" & Me.hDC
Debug.Print "hdc = " & hDC
Debug.Print "form1.hdc = " & Form1.hDC
Dim deskHwnd As Long
Dim deskHDC As Long
deskHwnd = GetDesktopWindow()
deskHDC = GetDC(deskHwnd)
Debug.Print "api desktop hdc = " & hDC
Call ReleaseDC(deskHwnd, deskHDC)
End Sub
'*************
Notice that all hdc values are identical. So my conclusion is that the only
time you would need to call an API for this is if you wanted to try to
support multiple monitors with different resolutions via
EnumDisplayMonitors() or some such. Just use hDC - it works!
Also, according to the docs, Tom is correct - passing 0& to GetDC should
return the Screen DC:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/...
_4esj.asp
However the DC I get when I pass a 0& is different from the DC I get from
the API when I pass GetDeskTopWindow(). This has bitten me in the past and
I wonder if some graphics guru out there could explain it to me???
To illustrate, the above sample code returns a different DC value if I use
GetDC(0) - try it!
FWIW,
Ray Mercer
MS-MVP Visual Basic