Link to home
Start Free TrialLog in
Avatar of WillowBrown
WillowBrown

asked on

View/Change Screen resolution from within my program

I am writing a program which is best viewed in a resolution os 1024 x 786. I need for the program to test the current screen res and change it to a higher res if too less than 1024 x 768, then change it back again to original setting after program closes.
Avatar of JensUniweb
JensUniweb
Flag of Sweden image

First of all. What platform are you talkning about???

If your talking about Windows I'm not sure you realy programaticly can change the resolution. What you can do is to create a virtual screen that is another resolution. But that will take you away from normal windows. You normaly do this when you want to draw grafics on the full screen using DirectX or OpenGL.
Avatar of lwinkenb
lwinkenb

GetSystemMetrics( SM_CXSCREEN) and GetSystemMetrics( SM_CYSCREEN) should give you the current screen resolution.
Then use ChangeDisplaySettings(LPDEVMODE lpDevMode, DWORD dwflags) to change the resolution to what you want.

When your program starts, save the current screen resolution before you change it.  Then when you program is closing, change the screen resolution back to what it was.
I would defently remove a program that do that at once. I choose the resolution. I know what works for me. Not the progam. :-) But it is nice knowing how to do it.
This is not a C++ language question and it off topic here.  A much better place for this would be the WINDOWS PROGRAMMING topic area:

https://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/

You should post a comment for the moderator in the CS topic area:

https://www.experts-exchange.com/Community_Support/

and ask them to move your question to the right topic area.  It helps things all around and benefits you by getting Windows Programming experts on your question vs. C++ experts here.
Avatar of WillowBrown

ASKER

Let me re-phrase the question because I am not trying to progran the windows API. So I know I am in the right forum. I am writing a time and labor report which has hundreds of edit boxes and takes up the entire screen of a screen set to 1024 x 768. Many users have their screen set to 600 x 600 or less and therefore, my program is to big to fit. I need the code in my program during initialization that gets the screen res. Saves it. Then changes the res to 1024 x 768. Then after the user closes the program, restores the res to original settings. I have looked at the DEVMODE and other structures and I can now retrieve the settings X and Y in integer format. That's great. But I am having trouble with the code that changes the res. I am using Borland C++ Builder Enterprise in Windows XP.
But you're working in the Windows enviroment. And you're wrinting a program for the Windows envorment. So you need to use the Windows API to do what you want. The DEVMODE structure is part of the Windows API. And the function you call to get it is part of the Windows API. So I think it you might get better helt in the Windows area. It's not a C++ question. Because it's not in C++ standard to choose screen resolution.

Even if you can change the resolution I would suggest writing it in the requirements that you need to run in 1024x768 resolution. It might be that if you change it you will crash the users machine. You may choose a resolution that the machine is not able to show. And after that the user need to know how to start in failsafe mode. And that they might not know how.

And also. At many companies the change resolution option is disabled by the support organisation so they don't need to handle all the problems that will create. So in my opinion. Write it in the documents that it is a requirement.

Another note. Writing software require a specific resolution might not be a good solution. Ofcurse there is always time when you have to.
>>I am not trying to progran the windows AP

Indeed you are.  C++ has ABSOLUTELY NO facility for changing screen resolution.  In fact, C++ lacks even the concept of a screen.

This is a Windows Programming question, pure and simple.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>This is a Windows Programming question, pure and simple.

Hi jhance,
I agree that this is a Windows Programming question; however, I still don't think it's inappropriate to keep this question in the C++ topic area.

Most questions posted in this topic area are not pure C++ question.
One of the reasons I participate in EE instead of the C++ newsgroup is because you can ask anything C++ programming related, and not have worry about a bunch of topic police.

When I want to find out how to program something in Windows or UNIX, I prefer to get an answer from another C++ programmer, then to get it from a generic programmer.

Furthermore, I also find I get answers quicker and a much better answer if I post them in the C++ topic area.

I have posted UNIX programming questions simultaneously in the UNIX programming topic area and in the C++ topic area.  And I always get an answer in the C++ topic area first.

My rule of thumb is that as long as the question can be posted with C++ code, then there should be no problem with keeping the question in the C++ topic area.
WillowBrown,

I agree with the other experts in that changing the screen resolution is generally frowned upon.


If you really feel that this functionality will benefit the user, then I highly recommend that at the minimum you add an option to your program so as to allow the user to disable this feature.

You should also consider that some disable users keep the screen resolution low so as to allow them to read the screen with the larger fonts.
Your program would be of no use to such handicap users if you force the resolution to a size they can’t read.
I agree in some degree that this question could be asked here. But on the other hand. The answer is a pure Windows API answer valid in every other language. Ofcurse here he got it in C/C++.

Anyway, I hope WillowBrown got the answer he wanted. Even if I still think it's not a good idee to change the resolution. The user should be the one selecting resolution to his/hers needs.
WillowBrown,

When I right programs, I usually try to target for a 800x600 window as my MAX.
If your program can not fit into a 800x600 window because it has too many fields, consider adding TABs to your window, and then seperating your fields into multiple tabs.