View Full Version : Switching Resolutions in Windows
soniCron
08-04-2005, 01:08 PM
I'm in an interesting spot right now. Though I've been coding off and on for 14+ years now, I haven't ever touched a single line of platform-specific code! This is a bad thing, because I am now in need of manually setting the Windows resolution to play the game fullscreen. Is there any way to non-destructively change the resolution? (Non-destructive, as in, doesn't rearrange the icons on the desktop or resize other windows like some games do. :mad: )
It's an interesting situation, because I'm not using DirectX or OpenGL, and I've also had zero experience with the Win32 API. I suppose I'll also need to know how to save the resolution to go back when the program exits as well. I'll not need to worry about color depth, however. Any thoughts?
ERoberts
08-04-2005, 01:19 PM
The ChangeDisplaySettings API works quite well, though _sometimes_ it can mess things up
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_7gz7.asp
dntoll
08-04-2005, 01:26 PM
Hm some display drivers make´s a mess off peoples desktops, I dont know any way to avoid it, maybe you can get the icons positions and types and store that before... ;-)
I think you can use EnumDisplaySettingsEx(...) to get the current settings in windows
And if you want to know which settings are supported by the hardware you should use EnumDisplayDevices and call EnumDisplaySettingsEx on the primary device...
Below is some code to change display settings in windows... (I did just cut and paste from my code so it might not be of much help... :confused:
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = m_width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = m_height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = m_bitsPerPixel; // Selected Bits Per Pixel
dmScreenSettings.dmDisplayFrequency = m_displayFreq;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
LOG_3_LAST_ERROR("ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)");
return false;
}
soniCron
08-04-2005, 01:33 PM
The ChangeDisplaySettings API works quite well, though _sometimes_ it can mess things up Very much thanks, ERoberts! :) When you say "_sometimes_ it can mess things up", what do you mean? Are there triggers for these screwups?
dntoll
08-05-2005, 01:43 AM
In my experience this is a driver issue... We use ChangeDisplaySettings and it made a mess of the desktop but only on Intel GPU´s but when they updated their drivers, we did not have that problem anymore...
ERoberts
08-05-2005, 02:08 AM
I've found that nowadays, ChangeDisplaySetting seems to just work, but I remember having problems with it back in the Win95/Win98 days. What it would do is not keep your desktop icons positions, not restore update frequency properly, or not make the windows big enough when you tried maximizing them afterwards.
I think it's not that big a problem nowadays. I guess you could take care to write your code so that it stores things that can go wrong befor using ChangeDisplaySettings, and to check that things are right after switching back, and if not correct them automatically.
digriz
08-05-2005, 03:20 AM
Although there's nothing wrong with the information people have given you here, i'd be cautious about changing peoples desktop modes.
My personal view is that people will not like you doing that. Even if it restored it correctly afterwards.
Is there a reason for not using opengl or directx?
soniCron
08-05-2005, 11:03 AM
Is there a reason for not using opengl or directx? Yes. I'm not using them to draw on the screen. That's not to say that I wouln't be happy with a solution that perhaps used a function from one of those libraries. It'd just need to be super compatible and work even under the worst conditions. I just want something stable that changes resolutions correctly every time. (And I'm going to a 640x480 mode with their desktop's color depth, so compatibility is a non-issue.)
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.