Determine the Correct Screen Dimensions

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 LongEnd TypePrivate Declare Function GetDesktopWindow Lib _	"user32" Alias "GetDesktopWindow" () As LongPrivate Declare Function GetWindowRect Lib _	"user32" Alias "GetWindowRect" (ByVal hwnd _	As Long, lpRect As RECT) As LongPublic Function ScreenWidth() As Single	Dim R As RECT	GetWindowRect GetDesktopWindow(), R	ScreenWidth = R.Right * Screen.TwipsPerPixelXEnd FunctionPublic Function ScreenHeight() As Single	Dim R As RECT	GetWindowRect GetDesktopWindow(), R	ScreenHeight = R.Bottom * Screen.TwipsPerPixelYEnd Function
See also  How AI Art Generators Can Save Time and Money for Startups

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist