Microsoft KB Archive/253940

= PRB: Incorrect Screen Object Width/Height After the Desktop Is Resized =

Article ID: 253940

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q253940



SYMPTOMS
Inside the Visual Basic IDE, the Screen object reports an incorrect value for the desktop width after the screen resolution is changed.

When the application is executing outside the IDE, the Width and Height properties of the Screen object return incorrect values if the resolution is changed from the Display Properties icon in the System Tray.



RESOLUTION
The GetDeviceCaps API function can be used to return the screen resolution in pixels. This workaround can be examined by removing the comment from the MsgBox command in the code provided in the "More Information" section of this article. The width and height pixel values returned by GetDeviceCaps can be converted to Twips by multiplying by Screen.TwipsPerPixelX and Screen.TwipsPerPixelY, respectively.



Steps to Reproduce Behavior
 In the Control Panel, use the Display option to change the screen resolution to 800 by 600 pixels. Create a new Standard EXE project in Visual Basic. Form1 is created by default.  Add the following code to the code window of Form1: Private Declare Function GetDeviceCaps Lib "gdi32" _ (ByVal hdc As Long, ByVal nIndex As Long) As Long

Const HORZRES = 8 Const VERTRES = 10

Sub Form_Load MsgBox "Width = " & Screen.Width & vbCrLf & _ "Height = " & Screen.Height ' Uncomment the following line to examine the workaround ' MsgBox "Width = " & GetDeviceCaps(Form1.hdc, HORZRES) & vbCrLf & _ "Height = " & GetDeviceCaps(Form1.hdc, VERTRES) End Sub  In the Control Panel, use the Display option to change the screen resolution to 640 by 480 pixels. Press the F5 key to run the program. Notice that the width of the screen, in Twips, is incorrectly reported as the screen height.

Keywords: kbapi kbgdi kbprb kbideproject KB253940

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.