How to get screen size ?

  • Thread starter Thread starter Leo Luk
  • Start date Start date
L

Leo Luk

Do any one know how to obtain the screen size property via
VBA ? (For example 1280 by 1024, 1024 by 768 ...)

I have developed an application at home but it look aweful
when I try to run it at work because it was based on the
screen size used at home.

Help
 
http://support.microsoft.com/support/kb/articles/q148/3/95.asp
ACC: How to Determine the Current Screen Resolution (95/97)


'*****************************************************************
' DECLARATIONS SECTION
'*****************************************************************
Option Explicit
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 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 '
'*****************************************************************
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


==============
Posted by Laurent Longre, Programming 06/10/99

Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hdc As Long, _
ByVal nIndex As Long) As Long
Declare Function GetDC Lib "User32" (ByVal hWnd As Long) As Long
Declare Function ReleaseDC Lib "User32" (ByVal hWnd As Long, _
ByVal hdc As Long) As Long

Sub Test()
Dim DC As Long
DC = GetDC(0)
MsgBox "Resolution : " & GetDeviceCaps(DC, 8) _
& " * " & GetDeviceCaps(DC, 10) & " pixels"
ReleaseDC 0, DC
End Sub
==================

Option Explicit

Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As _
Long) As Long

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Public Function GSR() As String
GSR = CStr(GetSystemMetrics(SM_CXSCREEN)) _
& "x" & CStr(GetSystemMetrics _
(SM_CYSCREEN))
End Function
===================
 
Declare Function GetSystemMetrics Lib "user32" (ByVal
nIndex As Long) As Long

sub test()
msgbox prompt:= GetSystemMetrics(0) & "x" &
GetSystemMetrics(1)
end

The above worked for me
 
Thanks for your response and appreciate your help. I copy
the code and try but keep geting 0x0 (I must have done
something incorrectly). I did try the one suggested by
Tom Ogilvy and is working.

Thanks and Merry Christmas

Leo
 
It is pretty much the same as the third piece of code i gave you:

Declare Function GetSystemMetrics Lib "user32" _
(ByVal nIndex As Long) As Long

Sub test()
MsgBox prompt:=GetSystemMetrics(0) _
& "x" & GetSystemMetrics(1)
End Sub

Worked for me. Probably a word wrap problem.
 
Back
Top