ChangeDisplaySettingsEx

[This is preliminary documentation and subject to change.]

The ChangeDisplaySettingsEx function changes the settings of the display device specified in the lpszDeviceName parameter to the graphics mode specified in the lpDevMode parameter.

LONG ChangeDisplaySettingsEx(
  LPCSTR lpszDeviceName,
  LPDEVMODE lpDevMode,  
  HWND     hwnd,
  DWORD dwflags         
  LPVOID lParam
);
 

Parameters

lpszDeviceName
Pointer to a null-terminated string that specifies the display device whose graphics mode the function will obtain information about. See EnumDisplayDevices for further information on the names associated with these display devices.

The lpszDeviceName parameter can be NULL. A NULL value specifies the default display device.

lpDevMode
Pointer to a DEVMODE structure that describes the graphics mode to switch to. The dmSize member must be initialized to the size, in bytes, of the DEVMODE structure. The dmDriverExtra member must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure.

You can use the following members of the DEVMODE structure.
Member Meaning
dmBitsPerPel Bits per pixel
dmPelsWidth Pixel width
dmPelsHeight Pixel height
dmDisplayFlags Mode flags
dmDisplayFrequency Mode frequency
dmPosition Windows 98, Windows NT 5.0 and later: Position of the device in a multi-monitor configuration.

In addition to setting a value in one or more of the preceding DEVMODE members, you must also set the appropriate flags in the dmFields member. The flags indicate which members of the DEVMODE structure are used for the display settings change. If the appropriate bit is not set in dmFields, the display setting will not be changed. Set one or more of the following flags:
Flag Meaning
DM_BITSPERPEL Use the dmBitsPerPel value.
DM_PELSWIDTH Use the dmPelsWidth value.
DM_PELSHEIGHT Use the dmPelsHeight value.
DM_DISPLAYFLAGS Use the dmDisplayFlags value.
DM_DISPLAYFREQUENCY Use the dmDisplayFrequency value.
DM_POSITION Windows 98, Windows NT 5.0 and later: Use the dmPosition value.

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.

hwnd
Must be NULL.
dwflags
Indicates how the graphics mode should be changed. The dwflags parameter can be one of the following.
Flag Meaning
0 The graphics mode for the current screen will be changed dynamically.
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.
CDS_TEST The system tests if the requested graphics mode could be set.
CDS_FULLSCREEN The mode is temporary in nature.

Windows NT: 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_SET_PRIMARY This device will become the primary device.
CDS_RESET The settings should be changed, even if the requested settings are the same as the current settings.
CDS_SETRECT The lParam message parameter specified in the WM_DISPLAYCHANGE message sent to all applications should be treated as a pointer to a RECT structure. This structure indicates the position of the display device in a multi-screen environment. An lParam of NULL means that the display device should be detached from the multi-screen environment.
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.

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.

Windows NT: 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.

lParam
Must be NULL.

Return Values

The ChangeDisplaySettingsEx function returns one of the following values.

Value Meaning
DISP_CHANGE_SUCCESSFUL The settings change was successful.
DISP_CHANGE_RESTART The computer must be restarted for the graphics mode to work.
DISP_CHANGE_BADFLAGS An invalid set of flags was passed in.
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_BADMODE The graphics mode is not supported.
DISP_CHANGE_NOTUPDATED Windows NT: Unable to write settings to the registry.

Remarks

To ensure that the DEVMODE structure passed to ChangeDisplaySettingsEx 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:

Parameters Meaning
wParam New bits per pixel
LOWORD(lParam) New pixel width
HIWORD(lParam) New pixel height

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Requires Windows 98 or later.
  Windows CE: Unsupported.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

Device Contexts Overview, Device Context Functions, ChangeDisplaySettings, CreateDC, DEVMODE, EnumDisplayDevices, EnumDisplaySettings, WM_DISPLAYCHANGE