tags:

views:

48

answers:

1

I am using the following code:

Private Sub Form_Load()
    ResWidth = Screen.Width \ Screen.TwipsPerPixelX
    ResHeight = Screen.Height \ Screen.TwipsPerPixelY
    ScreenRes = ResWidth & "x" & ResHeight
    MsgBox (ScreenRes)
End Sub

And several other similar codes I've googled for. The problem is, I always get a message box saying that my resolution is 1200x1200, although my actual resolution is 1920x1200. Why am I getting bad results?

+1  A: 

Not sure why that doesn't work, but you could tap into the Windows API.

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

And then when you need the screen width and height, define these constants:

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Then you can use GetSystemMetrics wherever you need it. If it makes more sense to add the declaration and constants to a Module (.BAS), then just make the declaration and constants public.

Dim width as Long, height as Long
width = GetSystemMetrics(SM_CXSCREEN)
height = GetSystemMetrics(SM_CYSCREEN)

GetSystemMetrics on Microsoft Support

derekerdmann