Sign in to follow this  

C++ Change screen resolution

This topic is 2397 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:

[code]

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();
}
[/code]

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 [img]http://public.gamedev.net/public/style_emoticons/default/cool.gif[/img]

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 ([url="http://msdn.microsoft.com/en-us/library/dd162611(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/dd162611(v=vs.85).aspx[/url]) 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 ([url="http://msdn.microsoft.com/en-us/library/dd183411(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/dd183411(v=vs.85).aspx[/url]) 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"][size="2"] [color="#000088"]if[/color] [color="#666600"](![/color][color="#000000"]windowed[/color][color="#666600"])[/color] [color="#666600"]{[/color][/size][/color]
[color="#1C2837"][size="2"] [color="#880000"] //setup the device mode[/color][color="#000000"]
DEVMODE devmode[/color][color="#666600"];[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmSize [/color][color="#666600"]=[/color] [color="#000088"]sizeof[/color][color="#666600"]([/color][color="#000000"]DEVMODE[/color][color="#666600"]);[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmPelsWidth [/color][color="#666600"]=[/color][color="#000000"] mGameWindow[/color][color="#666600"].[/color][color="#660066"]GetWidth[/color][color="#666600"]();[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmFields [/color][color="#666600"]|=[/color][color="#000000"] DM_PELSWIDTH[/color][color="#666600"];[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmPelsHeight [/color][color="#666600"]=[/color][color="#000000"] mGameWindow[/color][color="#666600"].[/color][color="#660066"]GetHeight[/color][color="#666600"]();[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmFields [/color][color="#666600"]|=[/color][color="#000000"] DM_PELSHEIGHT[/color][color="#666600"];[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmBitsPerPel [/color][color="#666600"]=[/color] [color="#006666"]32[/color][color="#666600"];[/color][color="#000000"]
devmode[/color][color="#666600"].[/color][color="#000000"]dmFields [/color][color="#666600"]|=[/color][color="#000000"] DM_BITSPERPEL[/color][color="#666600"];[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#880000"] //position the window to 0, 0[/color][color="#000000"]
mGameWindow[/color][color="#666600"].[/color][color="#660066"]SetPosition[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],[/color] [color="#006666"]0[/color][color="#666600"]);[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#880000"] //change screen resolution[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#660066"] ChangeDisplaySettings[/color][color="#666600"](&[/color][color="#000000"]devmode[/color][color="#666600"],[/color] [color="#006666"]0[/color][color="#666600"]);[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#666600"]}[/color] [color="#000088"]else[/color] [color="#666600"]{[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#880000"] //set screen resolution to initial settings[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#660066"] ChangeDisplaySettings[/color][color="#666600"](&[/color][color="#000000"]initDev[/color][color="#666600"],[/color] [color="#006666"]0[/color][color="#666600"]);[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#880000"] //position window in middle of the screen[/color][color="#000000"]
mGameWindow[/color][color="#666600"].[/color][color="#660066"]CenterScreen[/color][color="#666600"]();[/color] [/size][/color][color=#1C2837][size=2][color="#666600"]}[/color] [/size][/color]

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
[quote name='bluntman' timestamp='1306342498' post='4815650']
Your graphics card and monitor will only support a limited set of possible resolutions. You should use EnumDisplaySettings ([url="http://msdn.microsoft.com/en-us/library/dd162611%28v=vs.85%29.aspx"]http://msdn.microsof...1(v=vs.85).aspx[/url]) 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 ([url="http://msdn.microsoft.com/en-us/library/dd183411%28v=vs.85%29.aspx"]http://msdn.microsof...1(v=vs.85).aspx[/url]) carefully and check the return value for the specific error.
[/quote]

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? [img]http://public.gamedev.net/public/style_emoticons/default/sad.gif[/img] 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 [/size][/color][img]http://public.gamedev.net/public/style_emoticons/default/wink.gif[/img]

Anyway, got my problem fixed a different way last night, posted how to do it on my other thread: [url="http://www.gamedev.net/topic/602779-directx-9-switching-window-state/page__st__20"]Here[/url]

Share this post


Link to post
Share on other sites

This topic is 2397 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this