Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Apr 7, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Determine the Correct Screen Dimensions

The latest video drivers can change the display resolution without rebooting. Unfortunately, the Screen object doesn't always properly return the new display size; it only remembers the display size when the app first used it. This behavior appears to be driver-dependent, although it might be produced by the operating system (it occurs on my Windows NT machine but not on my Windows 98 system). If you need to determine screen dimensions at any time other than the Form_Load event, use the Windows API rather than the Screen object:
Private Type RECT
	Left As Long
	Top As Long
	Right As Long
	Bottom As Long
End Type
Private Declare Function GetDesktopWindow Lib _
	"user32" Alias "GetDesktopWindow" () As Long
Private Declare Function GetWindowRect Lib _
	"user32" Alias "GetWindowRect" (ByVal hwnd _
	As Long, lpRect As RECT) As Long
Public Function ScreenWidth() As Single
	Dim R As RECT
	GetWindowRect GetDesktopWindow(), R
	ScreenWidth = R.Right * Screen.TwipsPerPixelX
End Function
Public Function ScreenHeight() As Single
	Dim R As RECT
	GetWindowRect GetDesktopWindow(), R
	ScreenHeight = R.Bottom * Screen.TwipsPerPixelY
End Function
Matt Hart
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date