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.
EnumDisplaySettings(NULL, dwModeNum, &dvmd);
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 the original resolution fails.
How to Use
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.
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).
- ScreenResolution32 /w1024 /h768 /8
- ScreenResolution32 /D (this will display the available resolutions)
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.
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 stays 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.
Use them, abuse them, but don't blame me.
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.