3 out of 6 rated this helpful Rate this topic

ChangeDisplaySettings function

The ChangeDisplaySettings function changes the settings of the default display device to the specified graphics mode.

To change the settings of a specified display device, use the ChangeDisplaySettingsEx function.

Syntax

LONG ChangeDisplaySettings(
  __in  DEVMODE *lpDevMode,
  __in  DWORD dwflags
);

Parameters

lpDevMode [in]

A pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags parameter is the easiest way to return to the default mode after a dynamic mode change.

The dmSize member of DEVMODE must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member of DEVMODE must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure. In addition, you can use any or all of the following members of the DEVMODE structure.

MemberMeaning
dmBitsPerPelBits per pixel
dmPelsWidthPixel width
dmPelsHeightPixel height
dmDisplayFlagsMode flags
dmDisplayFrequencyMode frequency
dmPositionPosition of the device in a multi-monitor configuration.

 

In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the dmFields member to change the display setting.

ValueMeaning
DM_BITSPERPELUse the dmBitsPerPel value.
DM_PELSWIDTHUse the dmPelsWidth value.
DM_PELSHEIGHTUse the dmPelsHeight value.
DM_DISPLAYFLAGSUse the dmDisplayFlags value.
DM_DISPLAYFREQUENCYUse the dmDisplayFrequency value.
DM_POSITIONUse the dmPosition value.

 

dwflags [in]

Indicates how the graphics mode should be changed. This parameter can be one of the following values.

ValueMeaning
0

The graphics mode for the current screen will be changed dynamically.

CDS_FULLSCREEN

The mode is temporary in nature.

If you change to and from another desktop, this mode will not be reset.

CDS_GLOBAL

The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.

CDS_NORESET

The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.

CDS_RESET

The settings should be changed, even if the requested settings are the same as the current settings.

CDS_SET_PRIMARY

This device will become the primary device.

CDS_TEST

The system tests if the requested graphics mode could be set.

CDS_UPDATEREGISTRY

The graphics mode for the current screen will be changed dynamically and the graphics mode will be updated in the registry. The mode information is stored in the USER profile.

 

Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to change to that graphics mode.

If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_RESTART is returned.

If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and DISP_CHANGE_NOTUPDATED is returned.

Return value

The ChangeDisplaySettings function returns one of the following values.

Return codeDescription
DISP_CHANGE_SUCCESSFUL

The settings change was successful.

DISP_CHANGE_BADDUALVIEW

The settings change was unsuccessful because the system is DualView capable.

DISP_CHANGE_BADFLAGS

An invalid set of flags was passed in.

DISP_CHANGE_BADMODE

The graphics mode is not supported.

DISP_CHANGE_BADPARAM

An invalid parameter was passed in. This can include an invalid flag or combination of flags.

DISP_CHANGE_FAILED

The display driver failed the specified graphics mode.

DISP_CHANGE_NOTUPDATED

Unable to write settings to the registry.

DISP_CHANGE_RESTART

The computer must be restarted for the graphics mode to work.

 

Remarks

To ensure that the DEVMODE structure passed to ChangeDisplaySettings is valid and contains only values supported by the display driver, use the DEVMODE returned by the EnumDisplaySettings function.

When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following message parameters.

ParametersMeaning
wParamNew bits per pixel
LOWORD(lParam)New pixel width
HIWORD(lParam)New pixel height

 

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

ChangeDisplaySettingsW (Unicode) and ChangeDisplaySettingsA (ANSI)

See also

Device Contexts Overview
Device Context Functions
ChangeDisplaySettingsEx
CreateDC
DEVMODE
EnumDisplayDevices
EnumDisplaySettings
WM_DISPLAYCHANGE

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Compatibility with Windows 7
Shouldn't the compatibility issue on Windows 7 discussed at http://social.msdn.microsoft.com/Forums/en/windowsuidevelopment/thread/5bc2396d-1e0e-44fb-b73b-95f8dfc45684 be mentioned??
Test result may return false positive.
a call to ChangeDisplaySettings with CDS_TEST may succeed only to fail later with a DISP_CHANGE_BADMODE if the dmDisplayFrequency is wrong. I've seen this when taking the current resolution and just trying to change the dmPelsWidth&dmPelsHeight. i.e. a 1280x720@59 was changed to 1024x768@59, which tested ok, but failed to change, however 1024x768@60 did not fail.
Version Info Incorrect
The Minimum supported client/server is incorrect.
These functions were already supported long before windows 2000 (supported at least since NT4):
- ChangeDisplaySettings
- EnumDisplaySettings