Microsoft DirectX 9.0


The SetCooperativeLevel method determines the top-level behavior of the application. DDSCL_EXCLUSIVE level is needed to call functions that can have drastic performance consequences for other applications. In order to call Compact, change the display mode, or modify the behavior (for example flipping) of the primary surface, an application must have obtained exclusive level. If an application calls SetCooperativeLevel with DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN, DirectDraw will attempt to resize its window to full screen. An application must either set the DDSCL_EXCLUSIVE or DDSCL_NORMAL flags, and DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.

ModeX modes are only available if an application sets DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE. DDSCL_ALLOWMODEX cannot be used with DDSCL_NORMAL. If DDSCL_ALLOWMODEX is not specifed, EnumDisplayModes will not enumerate the ModeX modes, and SetDisplayMode will fail when a ModeX mode is requested. The set of supported display modes may change after using SetCooperativeLevel.

Because the ModeX modes are not supported by Windows, when in a ModeX mode you cannot lock the primary surface, blit to the primary surface, use GetDC on the primary surface, or use GDI with a screen DC. ModeX modes are indicated by the DDCAPS_MODEX flag in the ddscaps member of the DDSURFACEDESC structure returned by IDirectDrawSurface::GetCaps and EnumDisplayModes.


HRESULT  SetCooperativeLevel(
  HWND hWnd,
DWORD dwFlags



Window handle used for the application.


May be one of the following values.

Value Description
DDSCL_ALLOWMODEX Allow use of ModeX display modes.
DDSCL_ALLOWREBOOT Allow CTRL_ALT_DEL to function while in full screen exclusive mode.
DDSCL_EXCLUSIVE Application requests exclusive level.
DDSCL_FULLSCREEN Exclusive mode owner will be responsible for the entire primary surface. GDI can be ignored.
DDSCL_NORMAL Application will function as a regular Windows application.
DDSCL_NOWINDOWCHANGES Do not allow DirectDraw to minimize or restore the application window on activation.

Return Values

Value Description
DD_OK The method succeeded.
DDERR_INVALIDOBJECT DirectDraw received a pointer that was an invalid DirectDraw object.
DDERR_INVALIDPARAMS One or more of the input parameters is invalid.
DDERR_EXCLUSIVEMODEALREADYSET An attempt was made to set the cooperative level when it was already set to exclusive.
DDERR_OUTOFMEMORY DirectDraw does not have enough memory to perform the operation.
DDERR_HWNDALREADYSET The cooperative level has already been set. It can not be reset while the process has surfaces or palettes created.
DDERR_HWNDSUBCLASSED The window used by DirectDraw has been subclassed; this prevents DirectDraw from restoring the state.

See Also