Solved

Setting the screen resolution

Posted on 2001-09-14
10
176 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
isEverywhere  challenge 19 71
wait notify demo infinite loop 3 94
twoTwo  challenge 35 92
ShiftLeft challenge 21 76
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 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

9 Experts available now in Live!

Get 1:1 Help Now