Step 2: Determining the Application's Behavior

Before you can change the resolution of your display, you must at a minimum specify the DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN flags in the dwFlags parameter of the IDirectDraw2::SetCooperativeLevel method. This gives your application complete control over the display device, and no other application will be able to share it. In addition, the DDSCL_FULLSCREEN flag sets the application in exclusive (full-screen) mode. Your application covers the entire desktop, and only your application can write to the screen. The desktop is still available, however. (To see the desktop in an application running in exclusive mode, start DDEX1 and press alt + tab.)

The following example demonstrates the use of the IDirectDraw2::SetCooperativeLevel method:

HRESULT      ddrval; 
LPDIRECTDRAW lpDD;     // Already created by DirectDrawCreate 
 
ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | 
    DDSCL_FULLSCREEN); 
if(ddrval == DD_OK) 
{ 
    // Exclusive mode was successful. 
} 
else 
{ 
    // Exclusive mode was not successful. 
    // The application can still run, however. 
} 
 

If IDirectDraw2::SetCooperativeLevel does not return DD_OK, you can still run your application. The application will not be in exclusive mode, however, and it might not be capable of the performance your application requires. In this case, you might want to display a message that allows the user to decide whether or not to continue.

One requirement for using IDirectDraw2::SetCooperativeLevel is that you must pass a handle of a window (HWND) to allow Windows to determine if your application terminates abnormally. For example, if a general protection (GP) fault occurs and GDI is flipped to the back buffer, the user will not be able to return to the Windows screen. To prevent this from occurring, DirectDraw provides a process running in the background that traps messages that are sent to that window. DirectDraw uses these messages to determine when the application terminates. This feature imposes some restrictions, however. You have to specify the window handle that is retrieving messages for your application—that is, if you create another window, you must ensure that you specify the window that is active. Otherwise, you might experience problems, including unpredictable behavior from GDI, or no response when you press alt+tab.