Display size

  • Thread starter Thread starter Heapy
  • Start date Start date
The code is a bit ugly, but ut works. You need four API
calls and the function below:

Global Const WM_HORZRES = 8
Global Const WM_VERTRES = 10

Declare Function WM_apiGetDesktopWindow Lib "user32"
Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC Lib "user32" Alias "GetDC"
(ByVal hwnd As Long) As Long
Declare Function WM_apiReleaseDC Lib "user32"
Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long)
As Long
Declare Function WM_apiGetDeviceCaps Lib "gdi32"
Alias "GetDeviceCaps" (ByVal hdc As Long, ByVal nIndex As
Long) As Long

Function GetDisplayWidth() As Integer
'* Returns the width of the display/desktop
Dim DisplayHeight As Integer
Dim DisplayWidth As Integer
Dim hDesktopWnd As Long
Dim hDCcaps As Long
Dim iRtn As Integer

hDesktopWnd = WM_apiGetDesktopWindow()
hDCcaps = WM_apiGetDC(hDesktopWnd)
DisplayHeight = WM_apiGetDeviceCaps(hDCcaps, WM_VERTRES)
DisplayWidth = WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
iRtn = WM_apiReleaseDC(hDesktopWnd, hDCcaps)

GetDisplayWidth = DisplayWidth
End Function

Hope this helps!
 
Back
Top