Platform SDK: DirectX

Step 3: Change the Display Mode

[Visual Basic]

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

[C++]

After you set the application's behavior, you can use the IDirectDraw7::SetDisplayMode method to change the resolution of the display. The following example shows how to set the display mode to 640 × 480 × 8 bits per pixel (bpp).

HRESULT       hRet; 
LPDIRECTDRAW7 g_pDD;   // already created by DirectDrawCreateEx 

hRet = g_pDD->SetDisplayMode(640, 480, 8, 0, 0);
if (hRet != DD_OK)
{ 
    // The display mode changed successfully. 
} 
else 
{ 
    // The display mode cannot be changed. 
    // The mode is either not supported or 
    // another application has exclusive mode. 
} 
 

When you set the display mode, you should ensure that if the user's hardware cannot support higher resolutions, your application reverts to a standard mode that is supported by a majority of display adapters. For example, your application could be designed to run on all systems that support 640 × 480 × 8 as a standard backup resolution.

Note  IDirectDraw7::SetDisplayMode returns a DDERR_INVALIDMODE error value if the display adapter could not be set to the desired resolution. Therefore, you should use the IDirectDraw7::EnumDisplayModes method to determine the capabilities of the user's display adapter before trying to set the display mode.

Next: Step 4: Create Flipping Surfaces