954,228 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to detect Screen Resolution in VB6 ?

Is there any way or API to detect the Screen Resolution in VB 6.

dilip_singh3
Newbie Poster
24 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

What do you exactly mean?

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

check out this sample program.
don't forget to give your geedback.

Attachments Res.zip (3KB)
choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

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

QVeen72
Posting Shark
950 posts since Nov 2006
Reputation Points: 84
Solved Threads: 143
 

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

BC_Programming
Newbie Poster
8 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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.

SCBWV
Junior Poster
125 posts since Apr 2007
Reputation Points: 40
Solved Threads: 24
 

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

rjrodrig
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

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.

SCBWV
Junior Poster
125 posts since Apr 2007
Reputation Points: 40
Solved Threads: 24
 

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

rjrodrig
Newbie Poster
3 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

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

[email]gr3en39@gmail.com[/email]

gr3en39
Newbie Poster
2 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

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...

aka_amboy
Newbie Poster
17 posts since May 2009
Reputation Points: 10
Solved Threads: 3
 

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

Myron Thomas
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

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

AndreRet
Senior Poster
3,918 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You