IDirectDraw2::SetDisplayMode

HRESULT SetDisplayMode(DWORD dwWidth, DWORD dwHeight,

DWORD dwBPP, DWORD dwRefreshRate, DWORD dwFlags);

Sets the mode of the display-device hardware.

·Returns DD_OK if successful, or one of the following error values otherwise:

DDERR_GENERIC

DDERR_INVALIDMODE

DDERR_INVALIDOBJECT

DDERR_INVALIDPARAMS

DDERR_LOCKEDSURFACES

DDERR_NOEXCLUSIVEMODE

DDERR_SURFACEBUSY

DDERR_UNSUPPORTED

DDERR_UNSUPPORTEDMODE

DDERR_WASSTILLDRAWING

dwWidth and dwHeight

Width and height of the new mode.

dwBPP

Bits per pixel (bpp) of the new mode.

dwRefreshRate

Refresh rate of the new mode. If this parameter is set to 0, the IDirectDraw interface version of this method is used.

dwFlags

This parameter is currently not used and must be set to 0.

The IDirectDraw2::SetCooperativeLevel method must be used to set exclusive-level access before the mode can be changed. If other applications have created a DirectDrawSurface object on the primary surface and the mode is changed, those applications' primary surface objects return DDERR_SURFACELOST until they are restored.

As part of the IDirectDraw interface, this method did not include the dwRefreshRate and dwFlags parameters.

Interaction between the IDirectDraw::SetDisplayMode and IDirectDraw::SetCooperativeLevel methods differs from their IDirectDraw2 counterparts. That is, if an application uses the IDirectDraw versions of these interfaces to set the cooperative level and display modes according to the following steps, the original display mode must be restored by using the IDirectDraw::RestoreDisplayMode method.

1Call IDirectDraw::SetCooperativeLevel with the DDSCL_EXCLUSIVE flag to gain exclusive mode.

2Call IDirectDraw::SetDisplayMode to change the display mode.

3Call IDirectDraw::SetCooperativeLevel with the DDSCL_NORMAL flag to release exclusive mode.

However, if you use the IDirectDraw2 interface and follow the same steps, the original display mode will be restored when exclusive mode is lost.