Platform SDK: DirectX |
The information in this section pertains only to applications written in C and C++. See DirectDraw Visual Basic Tutorials.
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 hRet; LPDIRECTDRAW7 g_pDD; // already created by DirectDrawCreateEx hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if (hRet != 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 by specifying the DDSCL_NORMAL flag. 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 enables the user to decide whether to continue.
If you are setting the full-screen, exclusive cooperative level, you must pass your application's window handle to SetCooperativeLevel to enable Microsoft® Windows® to determine if your application terminates abnormally. For example, if a general protection (GP) fault occurs and the Graphics Device Interface (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 sent to the application 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.