Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my coding:

C++
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	DEVMODE dm;
	ZeroMemory(&dm, sizeof(dm));
	
   dm.dmSize = sizeof(dm);
   int index = 0;
   if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
   {

	  DWORD dwTemp = dm.dmPelsHeight;
      dm.dmPelsHeight= 800;
      dm.dmPelsWidth = 600;
	  dm.dmDisplayFlags =  DM_DISPLAYFLAGS;
	  dm.dmBitsPerPel = 16;
	  dm.dmFields = 16;
	  if(DISP_CHANGE_SUCCESSFUL  == ChangeDisplaySettings(&dm,0))
	  {
		  printf("\nSuccess\n");
	  }
	  else
	  {
		  printf("\nFailure\n");
	  }
	  
	return 0;
}


i want to change the screen resolution..

The above program i wrote for that one..

But it produces success even-through the changes not applied to the screen ..

Why?
Posted
Updated 31-Oct-11 1:36am
v2
Comments
Philippe Mori 31-Oct-11 18:22pm    
Very bad idea for a program to change screen resolution. Your users will hate you!

It seems that you've not fully specified which fields of DEVMODE are valid.

The value you set for flags is rather odd - 0x10 (corresponds to DM_SCALE)
You need to set a bit that indicates each of the valid fields of the structure.

Just change the line:
C++
dm.dmFields = 16;


To
C++
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;


Oh! Also, do you mean to set a 600x800 screen (as shown in code) or the more likely 800x600? When I tried that, the bits/pixel changed, though the screen res didn't - I also received a success result. Guess the best thing to do is to check that the actual values are the expected ones after an attempt to change the screen settings..

C++
//#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	DEVMODE dm;
	ZeroMemory(&dm, sizeof(dm));

   dm.dmSize = sizeof(dm);
   int index = 0;
   if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
   {

	  DWORD dwTemp = dm.dmPelsHeight;
	  dm.dmPelsWidth = 800;
	  dm.dmPelsHeight= 600;
	  dm.dmDisplayFlags =  DM_DISPLAYFLAGS;
	  dm.dmBitsPerPel = 16;
	  dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
	  if(DISP_CHANGE_SUCCESSFUL  == ChangeDisplaySettings(&dm,0))
	  {
		  printf("\nSuccess\n");
	  }
	  else
	  {
		  printf("\nFailure\n");
	  }
    }
    return 0;
}
 
Share this answer
 
Comments
@BangIndia 31-Oct-11 9:58am    
while running the program the screen got rotated. i want to avoid the rotation. how..

i try to use dm.dmDisplayOrientation = DMDO_0
But it gives error:
is not a member of '_devicemodeA'
Andrew Brock 31-Oct-11 10:15am    
The correct value is DMDO_DEFAULT.

This is about half way down the MSDN page at http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565(v=vs.85).aspx
enhzflep 31-Oct-11 10:28am    
In order to get access to the .dmDisplayOrientation, and the DMDO_DEFAULT (0°) you have to #define WINVER as being (at least) 0x0501 or higher ( I use 0x0600 )

You need to do this _before_ you include windows.h
Try this:
dm.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL;

Good luck!
 
Share this answer
 
Comments
@BangIndia 31-Oct-11 9:58am    
while running the program the screen got rotated. i want to avoid the rotation. how.. i try to use dm.dmDisplayOrientation = DMDO_0 But it gives error: is not a member of '_devicemodeA'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900