Sign in to follow this  

ChangeDisplaySettings troubles

This topic is 2658 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

Hi there,

I'm having no difficulty changing screen resolutions on my home PC. However, when I attempt to change screen resolutions on my laptop, it simply won't work.

I have been using ChangeDisplaySettings to do so. I have verified that the DEVMODEs that I am trying to change to on my laptop are supported by my monitor. However, display change always fails.

I believe ChangeDisplaySettingsEx might help me, however I am having difficulty figuring the parameters out. Regardless, do you think using the Ex version will change anything?

Here's essentially what I'm doing:

	// create some temporary variables
DEVMODE devmode;
devmode.dmSize = sizeof(DEVMODE);

// loop through video modes until we run out of them
for( unsigned int i = 0; ; i++ )
{
// make sure there are still more video modes to check out
if( EnumDisplaySettings( NULL, i, &devmode ) != 1 )
{
// terminate the loop
break;
}
// if there are more video modes
else
{
// check to see if this is the right fullscreen display mode
if( devmode.dmPelsWidth == this->fullscreen_screen_width
&& devmode.dmPelsHeight == this->fullscreen_screen_height
&& devmode.dmBitsPerPel == 32
&& devmode.dmDisplayFixedOutput == 0
&& devmode.dmDisplayFrequency == 60 )
{
// make it so
this->fullscreen_display_settings.dmSize = sizeof(DEVMODE);
EnumDisplaySettings( NULL, i, &this->fullscreen_display_settings );
break;
}
}
}

if( ChangeDisplaySettings( &this->fullscreen_display_settings,
CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
{
return 0;
}

Share this post


Link to post
Share on other sites
This smells:

if( EnumDisplaySettings( NULL, i, &devmode ) != 1 )

You should never be comparing directly to magic numbers like 1. According to the documentation, the return from EnumDisplaySettings can be any nonzero value for success. So you might possibly get weird results if it decides to return, say, 2 - which it is perfectly allowed to do.

Also, you should note the actual error returned from ChangeDisplaySettings, instead of just checking for success. Again, check the documentation, which in this case provides several helpful error codes that might explain what's going wrong on your laptop.


Just blindly changing to a different API function in hopes that it will magically work better is never a good idea. Instead, you should be trying to understand why your code is failing.

Share this post


Link to post
Share on other sites

This topic is 2658 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