IDirectDraw2::SetCooperativeLevel

HRESULT SetCooperativeLevel(HWND hWnd, DWORD dwFlags);

Determines the top-level behavior of the application.

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

DDERR_EXCLUSIVEMODEALREADYSET

DDERR_HWNDALREADYSET

DDERR_HWNDSUBCLASSED

DDERR_INVALIDOBJECT

DDERR_INVALIDPARAMS

DDERR_OUTOFMEMORY

hWnd

Window handle used for the application.

dwFlags

One or more of the following flags:

DDSCL_ALLOWMODEX

Allows the use of Mode X display modes.

DDSCL_ALLOWREBOOT

Allows CTRL+ALT+DEL to function while in exclusive (full-screen) mode.

DDSCL_EXCLUSIVE

Requests the exclusive level.

DDSCL_FULLSCREEN

Indicates that the exclusive-mode owner will be responsible for the entire primary surface. GDI can be ignored.

DDSCL_NORMAL

Indicates that the application will function as a regular Windows application.

DDSCL_NOWINDOWCHANGES

Indicates that DirectDraw is not allowed to minimize or restore the application window on activation.

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

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

Windows does not support Mode X modes; therefore, when your application is in a Mode X mode, you cannot use the IDirectDrawSurface2::Lock or IDirectDrawSurface2::Blt methods to lock or blit the primary surface. You also cannot use either the IDirectDrawSurface2::GetDC method on the primary surface, or GDI with a screen DC. Mode X modes are indicated by the DDSCAPS_MODEX flag in the DDSCAPS structure, which is part of the DDSURFACEDESC structure returned by the IDirectDrawSurface2::GetCaps and IDirectDraw2::EnumDisplayModes methods.

Because applications can use DirectDraw with multiple windows, IDirectDraw2::SetCooperativeLevel does not require a window handle to be specified if the application is requesting the DDSCL_NORMAL mode. By passing a NULL to the window handle, all of the windows can be used simultaneously in normal Windows mode.

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.