Step 3: Changing the Display Mode

After you have set the application's behavior, you can use the IDirectDraw2::SetDisplayMode method to change the resolution of the display. The following example shows how to set the display mode to 640×480×8 bpp:

HRESULT      ddrval; 
LPDIRECTDRAW lpDD;  // Already created 
 
ddrval = lpDD->SetDisplayMode(640, 480, 8); 
if(ddrval == 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:  IDirectDraw2::SetDisplayMode returns a DDERR_INVALIDMODE error value if the display adapter could not be set to the desired resolution. Therefore, you should use the IDirectDraw2::EnumDisplayModes method to determine the capabilities of the user's display adapter before trying to set the display mode.