Hi,

You dont need an API to know the Resolution.., Use Screen Object of VB:

msgbox "Width = " & Screen.Width/15  _
   & vbcrlf _
   & " Height = " & Screen.Height/15

Regards
Veena

Instead of using the constant 15 isn't it safer to use screen.twipsperPixelX and Screen.TwipsPerPixelY ?

Yes, use twipsperpixel... I recently found this changed on wide-screen flat panels, and if you don't adjust for it, some elements on your forms will look crappy.

I have the same issue. What I want to detect is the actual operating system under the control panel and detect that windows settings so that I can tell the user change the resolution. The screen method does not seem to work well. i have tested my code where I changed the resolution to a lower resolution, and someone made the comment the program looks crappy!

I agree. There's got to be a way to detect under start->Control Panel->Display->Settings-> screen Resolution Slide bar.

The specific question is how to fetch that resolution and evaluate it in your code? The dumb way would be to have a dialog box and tell the user to change it, but more elegant would be a way to detect it.

Does anyone know how to do this? There's got to be an API to acces that in the OS.

Regards,
Rj

Yes, the SysInfo control has an event called DisplayChanged which fires when the screen resolution has been changed. It has many others, including one for SysColorsChanged, several for battery status, power changes and device arrival/removal.

The answer to everyone's request is here. I knew there was an API out there to do so. this website has it http://cuinl.tripod.com/Tips/get_screen_resolutionAPI.htm


1. Download the API-GUIDE. Neat utility for all windows API and sample code. google it
www.devhood.com/Tools/tool_details.aspx?tool_id=563


Make a module and dump this code

Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Make a form and dump it on the Form_Load() procedure.

Private Sub Form_Load()
Dim Tmp As String
Tmp = GetSystemMetrics(SM_CXSCREEN) & _
"x" & GetSystemMetrics(SM_CYSCREEN)
MsgBox (Tmp)
End Sub

You will see that you can get the information you need.

RJ

Comments
This is a good poster with common sense straight to the point code

yes I believe i ve tried using the code already ====
====
all you really need is to discover controls in Visual Basic..

heres the code ive used:
i used it in the module so that i could easily call it:

Public Function ScreenResolution(f As Form) As String

Dim iWidth As Integer, iHeight As Integer

iWidth = Screen.Width \ Screen.TwipsPerPixelX
iHeight = Screen.Height \ Screen.TwipsPerPixelY
ScreenRes = iWidth & " X " & iHeight

End Function

gr3en39@gmail.com

Comments
No good code doesn't work

Howdy?

We're both NEWBIES here and as far as VB6 and being a newbie are concerned, I suggest you better opt for simple coding and explanations. You see, advanced coding might give you migraines or ulcers...

Try the suggestions offered to you here (specifically on using the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY techniques, which in my experience, are very simple to integrate and debug).

Now, if you want your program to detect changes in the screen resolution DURING RUN TIME, I suggest you do the coding WITHIN a timer subroutine. This means your program must stay memory-resident and check the screen resolution from time to time, say, every second. As your app checks the resolution, the values should be stored on two variables (say CurrentRes and NewRes, both being arrays to store the values of the screen resolution's height and width). Everytime CurrentRes and NewRes are detected as unequal, you can then trap the inequality and launch an appropriate routine to inform the user.

I can't give you here a thorough coding of this suggestion. Sorry, but you have to discover it by yourself through perseverance and diligence -- just the way I helped myself learn the simple nuances of VB6.

Good luck, Buddy...

What I am doing currently is designing two forms to open to the left of center under the assumption that user has high screen resolution, but putting a button on right-side form. If the resolution is low, user can't see left form. But, if user clicks button on right-form, both forms become centered. This works. I would, however, like to detect what the screen resolution is, so I will know to programatically to set forms in center when necessary.
Myron Thomas

If you read through all the other posts (FROM 2007!) you will see that there are multiple ways of getting the screen resolution.

This article has been dead for over six months. Start a new discussion instead.