Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check & Change display resolution

Status
Not open for further replies.

jbs

Programmer
Feb 19, 2000
121
US
I need to have my program programatically check that the screen resolution is set to 800x600. If it's not 800x600 I then need to save the existing resolution, change it to 800x600 and then return it back to the initial resolution when my program is done.

I am not using MFC...looking for a straight forward API solution.

Thanks for any help that can be provided.

/jbs
 
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>

enum
{
RES_X=800,
RES_Y=600,
BPP =16
};

void DisplayVerify( LONG lResult );

int main()
{
DEVMODE dMode;
LONG lResult;
int x,y;

x=GetSystemMetrics( SM_CXSCREEN );
y=GetSystemMetrics( SM_CYSCREEN );

if( x!=RES_X && y!=RES_Y )
{

dMode.dmFields= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
dMode.dmPelsWidth=RES_X;
dMode.dmPelsHeight=RES_Y;
dMode.dmBitsPerPel=BPP;

lResult=ChangeDisplaySettings( &dMode,CDS_UPDATEREGISTRY );
DisplayVerify( lResult );
}
else
std::cout << &quot;The display is set at 800x600&quot; <<
std::endl;

return 0;
}

void DisplayVerify( LONG lResult )
{
switch( lResult )
{
case DISP_CHANGE_SUCCESSFUL: std::cout << &quot;<SUCCESS>&quot;; break;

case DISP_CHANGE_RESTART :
case DISP_CHANGE_BADFLAGS :
case DISP_CHANGE_FAILED :
case DISP_CHANGE_BADMODE :
case DISP_CHANGE_NOTUPDATED: std::cout << &quot;<ERROR>&quot;;
default:
break;
}

}

This should get you started. Mike L.G.
mlg400@linuxmail.org
 
LiquidBinary,

Just wanted to say think you for taking the time to answer my question. The code was helpful and I learned a lot from it.

Thanks,

jbs
 
LiquidBinary me thinks you'd be easier doing a FAQ for this one, it does appear to be quite popular.



William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top