Setting the Cooperative Level

[Previous] [Next]

Once a DirectDraw device is created, you need to set the cooperative level. The cooperative level, which is used for DirectDraw, DirectSound, and DirectInput, specifies how your code will work with the system and other applications. You must set the cooperative level before you call other DirectDraw methods or they might fail, depending on what the other applications are doing.

In DirectDraw, cooperative levels are used mainly to determine whether an application is running as a windowed application or a full-screen program with exclusive access to the display. In DirectX 7, you use the IDirectDraw7::SetCooperativeLevel method to set the cooperative level of DirectDraw. The standard cooperative level places DirectDraw in a windowed mode that doesn't allow you to change the primary surface's palette or perform page flipping. For most game development, this restriction wouldn't be acceptable because the palette sometimes needs to change and page flipping is definitely required for realistic 3D. I'll explain page flipping in detail later in this chapter, when we get to that segment of code. For now, just remember that you often need to set the cooperative level to acquire exclusive, full-screen access rather than to run in windowed mode.

DirectDraw cooperative levels can also be used to do the following:

  • Prevent DirectDraw from rebooting if the user presses Ctrl+Alt+Del and from releasing exclusive control of the display
  • Enable the use of Mode X resolutions
  • Allow DirectDraw to maximize or minimize the application (when in windowed mode)
  • Indicate whether the palette will be manipulated

DirectDraw controls window activation events when in exclusive, full-screen mode. (No other applications will be fighting for display resources.) WM_ACTIVATEAPP messages are sent as needed to the window handle registered using the SetCooperativeLevel method. Because of this, since DirectDraw sends activation events to the top-level window only, you must subclass any child windows your application creates that require activation event messages.

The IDirectDraw7::SetCooperativeLevel method is declared as follows:

 HRESULT SetCooperativeLevel(     HWND hWnd,     DWORD dwFlags ); 

ParameterDescription
hWndThe window handle used for the application. This parameter is set to the calling application's top-level window. It can be NULL when the DDSCL_NORMAL flag is specified in the dwFlags parameter.
dwFlagsOne or more of the following flags:

DDSCL_ALLOWMODEX   Enables the use of Mode X display modes. This flag can be used if the DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN flags are present.

DDSCL_ALLOWREBOOT   Enables Ctrl+Alt+Del to function while in exclusive, full-screen mode.

DDSCL_CREATEDEVICEWINDOW Supported only in Windows 98 and Windows 2000. This flag indicates that DirectDraw is to create and manage a default device window for this DirectDraw object.

DDSCL_EXCLUSIVE Requests the exclusive level. This flag must be used with the DDSCL_FULLSCREEN flag.

DDSCL_FPUPRESERVE Indicates that the calling application cares about the floating-point unit (FPU) state and doesn't want Direct3D to modify it in ways visible to the application. This flag causes Direct3D to save and restore the state of the FPU whenever it modifies the FPU state.

DDSCL_FPUSETUP The system will attempt to keep the FPU set up for optimal Direct3D performance with single precision and exceptions disabled so that Direct3D won't need to set the FPU each time.

DDSCL_FULLSCREEN Indicates that the exclusive-mode owner will be responsible for the entire primary surface. The graphics device interface (GDI) can be ignored. This flag must be used with the DDSCL_EXCLUSIVE flag.

DDSCL_MULTITHREADED Requests multithread-safe DirectDraw behavior. This flag causes Direct3D to take the global critical section more frequently.

DDSCL_NORMAL Indicates that the application will function as a regular Windows application. This flag can't be used with the DDSCL_ALLOWMODEX, DDSCL_EXCLUSIVE, or DDSCL_FULLSCREEN flag.

DDSCL_NOWINDOWCHANGES Specifies that DirectDraw isn't allowed to minimize or restore the application window on activation.

DDSCL_SETDEVICEWINDOW Supported only in Windows 98 and Windows 2000. This flag indicates that the hWnd parameter is the window handle of the device window for this DirectDraw object. This flag can't be used with the DDSCL_SETFOCUSWINDOW flag.

DDSCL_SETFOCUSWINDOW Supported only in Windows 98 and Windows 2000. This flag indicates that the hWnd parameter is the window handle of the focus window for this DirectDraw object. This flag can't be used with the DDSCL_SETDEVICEWINDOW flag.

If you use the DDSCL_NORMAL flag, have multiple DirectDraw windows, and pass NULL as the window handle, the IDirectDraw7::SetCooperativeLevel method will allow all the windows to be used at the same time in normal windowed mode.

By using the exclusive, full-screen cooperative level, you can use the accelerator hardware on the system to its greatest advantage, which is one reason so many developers create games using full-screen mode. This mode allows page flipping, dynamic or custom palettes, and changing display resolutions. You need to keep in mind that in exclusive, full-screen mode, other applications can allocate surfaces and use DirectDraw, but only the application with exclusive access can change the display mode or palette.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net