C++ Change screen resolution

Started by
4 comments, last by malborojones 12 years, 10 months ago
Hellow, I'm trying to change the screen resolution to make it look like my window has gone full screen, from what I've gathered around the internet I've tried this:



if (!windowed)
{
//setup the device mode
DEVMODE devmode;
devmode.dmSize = sizeof(DEVMODE);
devmode.dmPelsWidth = mGameWindow.GetWidth();
devmode.dmFields |= DM_PELSWIDTH;
devmode.dmPelsHeight = mGameWindow.GetHeight();
devmode.dmFields |= DM_PELSHEIGHT;
devmode.dmBitsPerPel = 32;
devmode.dmFields |= DM_BITSPERPEL;

//position the window to 0, 0
mGameWindow.SetPosition(0, 0);
//change screen resolution
ChangeDisplaySettings(&devmode, 0);
} else {
//set screen resolution to initial settings
ChangeDisplaySettings(&initDev, 0);
//position window in middle of the screen
mGameWindow.CenterScreen();
}


initDev has the initial screen width and height in it. After calling this nothing seems to change, the windows borders disappear as they should when full screen is set on and they come back otherwise but the resolution doesn't change.

Any ideas how to achieve this?
Thanks, Mal cool.gif
Never refuse a cup of tea, that's how wars are started.
Advertisement
Your graphics card and monitor will only support a limited set of possible resolutions. You should use EnumDisplaySettings (http://msdn.microsoft.com/en-us/library/dd162611(v=vs.85).aspx) to determine the supported modes, then change mode to the one you want, while sizing and positioning your window to fill the screen. You should read the MSDN page for ChangeDisplaySettings (http://msdn.microsoft.com/en-us/library/dd183411(v=vs.85).aspx) carefully and check the return value for the specific error.
It's okay, I managed it in the end. Here is what I did for anyone that finds this:

[color="#1C2837"] [color="#000088"]if [color="#666600"](![color="#000000"]windowed[color="#666600"]) [color="#666600"]{
[color="#1C2837"] [color="#880000"] //setup the device mode[color="#000000"]
DEVMODE devmode[color="#666600"];[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmSize [color="#666600"]= [color="#000088"]sizeof[color="#666600"]([color="#000000"]DEVMODE[color="#666600"]);[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmPelsWidth [color="#666600"]=[color="#000000"] mGameWindow[color="#666600"].[color="#660066"]GetWidth[color="#666600"]();[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmFields [color="#666600"]|=[color="#000000"] DM_PELSWIDTH[color="#666600"];[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmPelsHeight [color="#666600"]=[color="#000000"] mGameWindow[color="#666600"].[color="#660066"]GetHeight[color="#666600"]();[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmFields [color="#666600"]|=[color="#000000"] DM_PELSHEIGHT[color="#666600"];[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmBitsPerPel [color="#666600"]= [color="#006666"]32[color="#666600"];[color="#000000"]
devmode[color="#666600"].[color="#000000"]dmFields [color="#666600"]|=[color="#000000"] DM_BITSPERPEL[color="#666600"];
[color="#1C2837"][color="#880000"] //position the window to 0, 0[color="#000000"]
mGameWindow[color="#666600"].[color="#660066"]SetPosition[color="#666600"]([color="#006666"]0[color="#666600"], [color="#006666"]0[color="#666600"]);
[color="#1C2837"][color="#880000"] //change screen resolution
[color="#1C2837"][color="#660066"] ChangeDisplaySettings[color="#666600"](&[color="#000000"]devmode[color="#666600"], [color="#006666"]0[color="#666600"]);
[color="#1C2837"][color="#666600"]} [color="#000088"]else [color="#666600"]{
[color="#1C2837"][color="#880000"] //set screen resolution to initial settings
[color="#1C2837"][color="#660066"] ChangeDisplaySettings[color="#666600"](&[color="#000000"]initDev[color="#666600"], [color="#006666"]0[color="#666600"]);
[color="#1C2837"][color="#880000"] //position window in middle of the screen[color="#000000"]
mGameWindow[color="#666600"].[color="#660066"]CenterScreen[color="#666600"](); [color=#1C2837][size=2][color="#666600"]}

initDev is a DEVMODE that's initialized with the initial screen resolution and depth, mGameWindow has the height and width of the window which I wanted to make "look full screen" although that didn't solve what I wanted (directx issues) the screen resolution changed as it should have. Just change dmPelsWidth and height to the resolution you want to use.
Never refuse a cup of tea, that's how wars are started.

Your graphics card and monitor will only support a limited set of possible resolutions. You should use EnumDisplaySettings (http://msdn.microsof...1(v=vs.85).aspx) to determine the supported modes, then change mode to the one you want, while sizing and positioning your window to fill the screen. You should read the MSDN page for ChangeDisplaySettings (http://msdn.microsof...1(v=vs.85).aspx) carefully and check the return value for the specific error.


that will work for imatateing FullScreen, but what i read is that code wont work with proper fullscreen.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

You shoud use EnumDisplaySettings to initialize the stucture, like this:

DEVMODE DisplayMode;
memset(&DisplayMode, 0, sizeof(DisplayMode));
if(!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &DisplayMode)){
MessageBox(NULL, "EnumDisplaySettings Failed ???", "Error!", 0);
return false;
}
DisplayMode.dmPelsWidth = Width;
DisplayMode.dmPelsHeight = Height;
//DisplayMode.dmBitsPerPel = 32;
int ChangeDisplayResult = ChangeDisplaySettings(&DisplayMode, CDS_FULLSCREEN);
if(ChangeDisplayResult != DISP_CHANGE_SUCCESSFUL){
MessageBox(NULL,"Error: Failed to change display mode.", "Error", 0);
return false;
}
Who voted me down? sad.gif Anyway, ye, it's something like that I used to initialise "initDev" at program start so that it knows what to switch back to when the program is exited.
I wouldn't have been able to use what you've done there "[color=#1C2837][size=2]ChangeDisplaySettings(&DisplayMode, CDS_FULLSCREEN)" because actually setting the widow to full screen was causing my directx device to be lost. I would imagine that would work fine for any other program though wink.gif

Anyway, got my problem fixed a different way last night, posted how to do it on my other thread: Here
Never refuse a cup of tea, that's how wars are started.

This topic is closed to new replies.

Advertisement