devxlogo

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

devx-admin

Share the Post: