georgesOne
Technical User
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
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