DirectX SDK

Step 2: Determine the Application's Behavior

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.

[C++]

Before you can change the resolution of the display, you must at a minimum specify the DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN flags in the dwFlags parameter of the IDirectDraw7::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 SetCooperativeLevel method:

HRESULT      ddrval; 
LPDIRECTDRAW7 lpDD;     // Already created by DirectDrawCreateEx 
 
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 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.

If you are setting the full-screen, exclusive cooperative level, you must pass your application's window handle to SetCooperativeLevel 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.

Next: Step 3: Change the Display Mode