Click here to Skip to main content
Licence 
First Posted 17 Apr 2003
Views 118,961
Downloads 3,317
Bookmarked 25 times

Article On Screen Resolution

By Barretto VN | 17 Apr 2003
Article on changing screen resolution.
10 votes, 35.7%
1
5 votes, 17.9%
2
2 votes, 7.1%
3
4 votes, 14.3%
4
7 votes, 25.0%
5
2.69/5 - 28 votes
μ 2.63, σa 2.92 [?]

Sample Image - ScreenResolution.gif

Introduction

Recently while developing an accounting application for a client who lives about 300 miles away from me, I realized that I had developed the various windows to suit my screen resolution. A few questions came to my mind before I gave him the setup files: Will his screen have the same resolution? If he changes it one-time on my instructions, what happens if he changes it for some reason? I found that the best option would be to include in the code, some lines which change the resolution as per my requirements at the start of the application and revert back to what was original, at the end of the application.

I found some helpful articles in MSDN which I used to develop these projects. This article consists of the following 3 projects.

  • ScreenResolution - Window GUI Application
  • ScreenResolution32 - Console Utility
  • ScrResOCX - ActiveX Control

About The Code

You retrieve the DEVMODE structure with a call to EnumDisplaySettings. Then modify the retrieved DEVMODE structure to your requirements and pass the structure to ChangeDisplaySettings() to change the resolution.

DEVMODE dvmd;
EnumDisplaySettings(NULL, dwModeNum, &dvmd);
ChangeDisplaySettings(&dvmd, 0);
// parameter 2 can be either CDS_TEST , CDS_UPDATEREGISTRY OR 0 (temporary)

Problems Encountered

While attempting to change the resolution to a very high value, for example (1600x1200), the system goes into a loop. The function (ChangeDisplaySettings()) returns success and all attempts to SetTimer() to change back to original resolution fails.

How to Use

ScreenResolution

This is a normal Windows GUI application which starts as shown in the image above. Select the resolution you want to set and click on "Change Res" button. If the change is possible (read the Known Problems section), you have two options to make the changes: Temporary, Write changes to registry to make change permanent or revert back to the original resolution. Note: temporary change means that if you re-boot your system, the original screen resolution will be restored not the changed resolution. An application icon is created in the System Tray (not very essential) and you can hide the application by selecting Hide from the menu.

ScreenResoution32

This sub-project is basically meant for use inside other applications developed in Visual Basic, FoxPro, Delphi PowerBuilder, VC++ etc. You invoke the executable by passing parameters: width, height, frequency, like this in Visual Basic.

Shell ("C:\ScreenResolution32\Debug\ScreenResolution32 /w800 /h600 /b16")

You can also test it in Windows by selecting from the Start bar, "Run/Browse". Then select the application and add the parameter as shown in the line of code above: "Shell ..."

You can also open a MS-DOS window and move to the location of the application by typing the following command for example (press Enter after each command).

  • CD\ScreenResolution32\Debug
  • ScreenResolution32 /w1024 /h768 /8

    OR

  • ScreenResolution32 /D (this will display the available resolutions)

ScrResOCX

You can use this control in applications which allow hosting of Active-X controls like Visual Basic, HTML, FoxPro etc. Given below are the instructions for using this control in Visual Basic. Download the Demo applications zip file and unzip the files OR build the OCX from the ScrResOCX project source.

  • Start Visual Basic
  • Create a Standard Exe project
  • Select Project/Components from menu
  • On the Controls tab, click Browse
  • Select the ScrResOCX.ocx file which you unzipped from the demo zip file
  • Click Apply
  • Click Close
  • Drag the newly added item (icon of computer screen) on the form
  • Add a command button to the form
  • In the Command1_Click() function, type the following line:
    ScrResOCX1.ScreenWidth = 1024
    ScrResOCX1.ScreenHeight = 768
    ScrResOCX1.ScreenBits = 8
    ScrResOCX1.ChangeResolution
  • Run the application
  • Click on the command button

Known Problems

When you change resolution from low to high, for example (800x600 to 1024x768), the size of Windows Start bar remains the same, move the Start bar to the bottom of the Desktop and it will resize to the Desktop width.

On my screen, the application shows displayable screen resolutions 1280x1024 and 1600x1200 etc., with frequencies of 4, 8 and 16, but when I try to set any of these resolutions, my monitor stay blank for a very long time due to which I have to re-boot the system. This is not a very serious problem since the call to change resolution (ChangeDisplaySettings()) is temporary and not to the Registry.

In case, if while changing the resolution, the system runs into trouble, start the system in "Safe Mode" and change the resolution to the desired by left clicking on the desktop area, selecting properties and from the displayed window, selecting the settings tab and moving the slider in the "Screen Area" box and clicking Apply.

History

New article.

Use them abuse them but don't blame me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Barretto VN



India India

Member
Nothing to boast about

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHas anybody seen my tool bar ? PinmemberPeter Harbord4:22 29 Apr '04  
Generalit's not that crazy Pinmemberphilipcunningham0:27 1 Mar '04  
GeneralRe: it's not that crazy PinmemberBarretto VN1:03 2 Mar '04  
GeneralIts useful to get the screen res too PinsussFrancisco Aguirre7:04 14 Nov '03  
GeneralRe: Its useful to get the screen res too PinmemberBarretto VN1:57 12 Dec '03  
GeneralThere is actually a better way... Pinmemberalman14:56 22 Apr '03  
GeneralRe: There is actually a better way... PinmemberBarretto VN2:17 6 Sep '03  
GeneralComplainers miss the value PinmemberAnswers20007:31 19 Apr '03  
GeneralRe: Complainers miss the value PinmemberJohn M. Drescher7:07 21 Apr '03  
GeneralAdmin remotely change screen resolution ! PinmemberKochise6:06 4 Sep '03  
GeneralThanks PinmemberBarretto VN23:45 11 Oct '03  
QuestionWhy so much anger? PinmemberBartosz Bien12:19 18 Apr '03  
AnswerRe: Why so much anger? Pinmemberdog_spawn14:31 18 Apr '03  
GeneralRe: Why so much anger? PinmemberBartosz Bien22:04 18 Apr '03  
GeneralStopping post garbage-level articles, Man! Pinsussprogrammer2003a9:51 18 Apr '03  
GeneralRe: Stopping post garbage-level articles, Man! PinmemberJohn Simmons / outlaw programmer10:01 18 Apr '03  
GeneralRe: Stopping post garbage-level articles, Man! PinmemberJohn M. Drescher10:10 18 Apr '03  
GeneralRe: Stopping post garbage-level articles, Man! PinmemberEarl Allen21:55 22 Apr '03  
GeneralRe: Stopping post garbage-level articles, Man! PinmemberWREY22:32 22 Apr '03  
GeneralTell us you're joking.... PinmemberJim A. Johnson8:39 18 Apr '03  
GeneralThanks PinmemberJohn M. Drescher5:54 18 Apr '03  
GeneralThis is crazy! PinmemberPaul A. Howes4:43 18 Apr '03  
GeneralRe: This is crazy! PinmemberJohn Simmons / outlaw programmer4:55 18 Apr '03  
GeneralRe: This is crazy! PinmemberRama Krishna8:47 18 Apr '03  
GeneralRe: This is crazy! Pinmembermwilliamson14:54 18 Apr '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 18 Apr 2003
Article Copyright 2003 by Barretto VN
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid