DirectX SDK

Step 2: Test for Hardware Overlay Support

[Visual Basic]

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

[C++]

After initializing DirectDraw, you need to verify that the device supports overlay surfaces. Because DirectDraw doesn't emulate overlays, if the hardware device driver doesn't support them, you can't continue. You can test for overlay support by retrieving the device driver capabilities with the IDirectDraw7::GetCaps method. After the call, look for the presence of the DDCAPS_OVERLAY flag in the dwFlags member of the associated DDCAPS structure. If the flag is present, then the display hardware supports overlays; if not, you can't use overlay surfaces with that device.

The following example, taken from the Mosquito sample application, shows how to test for hardware overlay support:

BOOL AreOverlaysSupported()
{
    DDCAPS  capsDrv;
    HRESULT ddrval;
 
    // Get driver capabilities to determine Overlay support.
    ZeroMemory(&capsDrv, sizeof(capsDrv));
    capsDrv.dwSize = sizeof(capsDrv);
 
    ddrval = g_lpdd->GetCaps(&capsDrv, NULL);
    if (FAILED(ddrval))
        return FALSE;
 
    // Does the driver support overlays in the current mode? 
    // (Currently the DirectDraw emulation layer does not support overlays.
    // Overlay related APIs will fail without hardware support).  
    if (!(capsDrv.dwCaps & DDCAPS_OVERLAY))
        return FALSE;
 
    return TRUE;
} 

The preceding example calls the IDirectDraw7::GetCaps method to retrieve device driver capabilities. The first parameter for the call is the address of a DDCAPS that will be filled with information describing the device driver's capabilities. Because the application doesn't need information about emulation capabilities, the second parameter is set to NULL.

After retrieving the driver capabilities, the example checks the dwCaps member for the presence of the DDCAPS_OVERLAY flag using a logical AND operation. If the flag isn't present, the example returns FALSE to indicate failure. Otherwise, the example returns TRUE to indicate that the device driver supports overlay surfaces.

In your code, this might be a good time for you to check the dwMaxVisibleOverlays and dwCurrVisibleOverlays members in the DDCAPS structure to ensure that no other overlay surfaces are in use by other applications.

Next: Step 3: Create an Overlay Surface