Solved

Setting the screen resolution

Posted on 2001-09-14
10
175 Views
Last Modified: 2013-11-20
Hey,

     I was wondering if there was a way to actually set the screen resolution, eg. to 1024x720, from C++, in a way that would be compatible with MFC?  I know there's a way to get what the current settings are, but I haven't figured out how to actually set the settings.

     Sample source greatly appreciated.

     Thanks in advance.
0
Comment
Question by:fcp_lead
10 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 100 total points
ID: 6484345
You could warn the user then start up the windows desktop applet if the screen resolution doesn't fit your App's requirements.
Use "CONTROL.EXE DESK.CPL" as the parameters of the new process.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6484366
You can get a little closer to the target by execing:

  RUNDLL32.EXE shell32.dll,Control_RunDLL desk.cpl,,3

Try it from the Start/Run... command.

I'd like to add that...
even if you can find a way to change the system screen resolution programmatically, it would be a *very bad* idea.   Those kinds of decisions need to be made by the user and/or the system administrator.  A wrong setting can kill Windows until a technical expert can get around to fixing things.

-- Dan
0
 
LVL 32

Expert Comment

by:jhance
ID: 6484521
I'd be interested to know how to do this as well...

It's my understanding that there is no Windows API to do this and that the DISPLAY driver itself implements some method (if needed) to control the resolution and that the mechanism by which it is controlled is therefore up to the individual driver maker.
0
 
LVL 1

Expert Comment

by:MRNMurthy
ID: 6484594
Hi,

I don't it is programmatically posible, I will try once.

From

MRN Murthy
0
 
LVL 1

Expert Comment

by:TarekEslim
ID: 6485543
In MFC, you can use the function: ChangeDisplaySettings and/or ChangeDisplaySettingsEx

It uses the DevMode structure parameter. It includes all properties about devices (Display, Printer, ...)

The function GetDeviceCaps retrieve the device information (Display device also)

See the MSDN help on these commands you will find full details.

Regards

Tarek
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 6486742
Further to my first post.  I would NOT recommend trying to change the settings yourself, let the user have the option to do so if they wish.  (I hate programs that alter MY setup of MY workstation without asking for permission.)

If you need to have the setting changed then you can start the display applet with createprocess and monitor the process until it finishes then recheck the settings.  If not suitable then fail gracefully.
If you need some code to do this creating/waiting then I can dig some up for you from one of my apps.

Any further questions?
0
 

Expert Comment

by:a_mellouk
ID: 6511890

This is the way to do it
exemple

CDC *pDC = GetDC();
int Hor = pDC->GetDeviceCaps(HORZRES);

if (Hor < 1024)
 //yor code
 .
 .
 .

ReleaseDC(pDC);
//see MSDN for aditional information
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6802878
hi fcp_lead,
Are you still interested in this question?  If so, you must reject the nonesense answer propose by a_mellouk so that other experts will comment.

a_mellouk,
Please post comments like everybody else.  Also, take a moment and read the questions before proposing anything at all.  Thanks!

-- Dan

0
 
LVL 11

Expert Comment

by:griessh
ID: 7202241
Unless there is objection or further activity,  I will suggest to accept

     "AndyAinscow"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7220578
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now