Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi I'm new to API calls, so plea

Status
Not open for further replies.

TBaz

Technical User
Jun 6, 2000
65
ES
Hi

I'm new to API calls, so please bear with me if this is a stupid question...

I'm trying to get the screen resolution of the Windows desktop using gdi32.dll - function "GetDeviceCaps". (I've successfully used "GetSystemMetrics" in user32.dll, but that returns the current window size - not the desktop).

In a VB example on the net, I've come across a call which uses the parameters:

XResolution = GetDeviceCaps(hDC, HORZRES)

I'm not using VB, but I am assuming that HORZRES is a subfunction and hDC is the handle of the window I'm getting the resolution of.

If not, would someone be good enough to tell me what 'hDC' is and if I am correct, how to get the correct value to use for hDC with regards to the Windows desktop.

Thanks in advance...

BC


 
Sorry - I was so involved in writing my message I forgot to put a topic title!

There doesn't appear to be a way to edit this post to add one. :(

BC
 

HDC = Handle Device Context. A printer has a HDC as does each window and you could use the devicecapabilities with a devmode structure to get the info you want.

Good Luck


 
I'm still not getting anywhere I'm afraid - as I'm using a DirectX screen, the calls are simply returning the current screen size.

My desktop is 1024x768 and the window I am writing my program in is 800x600. GetSystemMetrics is the only call I can get to work as I can't get the hDC of the desktop to use with GetDeviceCaps (all combinations simply return 0).

Can anyone help with a bit of code to demonstrate what I'm after please?

Thanks in advance...

BC
 
You can get the screen resoulution with this simple code

Private Sub Command1_Click()
Dim lheight As Long
Dim lWidth As Long

lheight = Screen.Height
lWidth = Screen.Width

lheight = lheight / Screen.TwipsPerPixelY
lWidth = lWidth / Screen.TwipsPerPixelX

MsgBox lWidth & " x " & lheight
End Sub

Regards,

Manoj
 

ManojShinde,

Evendently you are assuming that TenerifeBarrie is using VB. This is a Windows API forum that has nothing to do with VB.

TenerifeBarrie,

You may be able to use the API of FindWindow to get the Desktop HDC.

Just a thought

Good Luck

 
You can use EnumDisplaySettings...

Maybe you can figure out how to use it in this code (VB):

Option Explicit
Const ENUM_CURRENT_SETTINGS As Long = -1&
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean

Private Sub Form_Load()
Dim DevM As DEVMODE
Call EnumDisplaySettings(0&, ENUM_CURRENT_SETTINGS, DevM)
Debug.Print "Current screen width: " & DevM.dmPelsWidth & " pixels"
Debug.Print "Current screen height: " & DevM.dmPelsHeight & " pixels"
Debug.Print "Current color depth: " & DevM.dmBitsPerPel & " bits/pixel"
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top