Jump to content
  • Advertisement
Sign in to follow this  
malborojones

C++ Change screen resolution

This topic is 2612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!