Changing windows resolution temporarly

Started by
2 comments, last by Karim 18 years ago
Hi all, My question is about making the computer change its resolution to (800x600 for example) as i enter the program. and back to the original resolution as i exit the program (CORRECTLY OR BY END-TASK etc...). I know how to set back the resolution when i end my program correctly, but this is not enough. The program may crash or simply the power can be cut off from the house while the user is running my program on his computer, so when he turns on the computer again, he will find his desktop's resolution weird. does anyone know a solution? N.B. without directx nor openGL :) and i'm using VB.net as an alternative for this.. another good solution for me can be a strechable windows form that looks exactly the same on different resolutions. can this be done? thanx alot :)
Advertisement
From a usability point of view, changing resolutions is a Bad Thing(tm).

LCDs for example handle only one resolution well. Some monitors take a while to readjust to new resolution. User might not have the image h/v centered for your specific resolution, etc. Alt-tabing will not cause problems. It can rearange desktop icons. Also, messing with system settings is generally one of the worst things you can do.

The only "allowable" resolution changing by the application is usually limited to full screen exclusive applications (DirectX, OpenGL).

As for making application look the same on every screen, this isn't without downsides either.

Icons do not scale well, fonts will generally have problems adjusting precisely to exact resolution, users might have their font preferences set differently, they might be using font which does not scale as you need it to, rounding errors may exhibit strange artefacts, it may interfere with accesibility and similar.

When doing this, you need to work out the screen dimensions, the resolution of fonts for that screen (96, 120 or custom dpi), then based on those values recreate your window, adjust the font sizes in all controls, and set proper sizes.

I do not know exactly how this would be done in VB .Net, but I've done similar under Delphi (which, at least regarding components, has similar structure and design). I defined my entire GUI in "metric" units, then when I had to create the GUI, I'd just apply a transformation from metric to screen dimensions. This way, if my application had a button "2cm by 1cm", it looked the same on all screens.

The reason I did this, is because despite several windows API methods provided for just that, they were extremly unreliable, especially with regard to font sizes. Some of the scaling functions also incorrectly (either due to user settings or internationalization differences) converted between screen resolutions, which resulted in GUI being completely broken on some systems.

My general advice would be not to do it, but if you have to, you'll need to look into manually configuring the GUI on launch.
Pass CDS_FULLSCREEN into the dwFlags parameter. That tells Windows that it's a temporary change and the resolution should be reset no matter what.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Antheus, thanks alot for your help and time. Promit, you got it man! i just did exactly what you said and it worked just fine and exactly as i wanted.. thanx for your care to both of you :)

and for the people that will read this forum and use VB.net, you pass the integer 4 or &H4 instead of writing CDS_FULLSCREEN to be understood by the VB.net compiler.

the integers (longs) that resemble dw.flags are written as follows:

CDS_FULLSCREEN is &h00000004
CDS_GLOBAL is &h00000008
CDS_NORESET is &h10000000
CDS_RESET is &h40000000
CDS_SET_PRIMARY is &h00000010
CDS_SETRECT is &h20000000
CDS_TEST is &h00000002
CDS_UPDATEREGISTRY is &h00000001

Thanks again people, I really didn't know anything about this dw.flags although it seems to be one of the basics that everyone should know :)

(the function to pass this parameter to is ChangeDisplaySettings by the way)

Private Declare Auto Function ChangeDisplaySettings Lib "user32.dll" ( _
ByRef lpDevMode As DEVMODE, _
ByVal dwFlags As Int32 _
) As Int32

This topic is closed to new replies.

Advertisement