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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to get the screen resolution 1

Status
Not open for further replies.

georgesOne

Technical User
Jul 2, 2004
176
JP
Hi there,

I found this nifty VBA snippet to get the screen resolution.I would like to add something like that to a script, but I can not get it to work. Could anyone guide me in the right direction or suggest a working code to get the screen resolution?

VBA Code:

Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
'' NOTE: The following declare statements are case sensitive.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, rectangle As RECT) As Long
''*****************************************************************
'' FUNCTION: GetScreenResolution()
''
'' PURPOSE:
'' To determine the current screen size or resolution.
''
'' RETURN:
'' The current screen resolution. Typically one of the following:
'' 640 x 480
'' 800 x 600
'' 1024 x 768
''
''*****************************************************************
Sub ScreenResolution()
MsgBox GetScreenResolution
End Sub

Function GetScreenResolution() As String
Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long
hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function

Thanks, georges
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top