### Step 6: Hiding the Overlay Surface

When you do not need the overlay surface anymore, or if you simply want to remove it from view, you can hide the surface by calling the IDirectDrawSurface3::UpdateOverlay method with appropriate flags. Mosquito hides the overlay in preparation for closing the application using the following code:

void DestroyOverlay()

{

if (g_lpddsOverlay){

// Use UpdateOverlay() with the DDOVER_HIDE flag to remove an overlay

// from the display.

g_lpddsOverlay->UpdateOverlay(NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);

g_lpddsOverlay->Release();

g_lpddsOverlay=NULL;

}

}

When the preceding example calls IDirectDrawSurface3::UpdateOverlay, it specifies NULL for the source and destination rectangles, because they are irrelevant when hiding the overlay. Similarly, the example uses NULL in the fourth parameter because overlay effects aren’t being used. The second parameter is a pointer to the target surface. Lastly, the example uses the DDOVER_HIDE flag in the fourth parameter to indicate that the overlay will be removed from view.

After the example hides the overlay, the example releases its IDirectDrawSurface3 interface and invalidates its global variable by setting it to NULL. For the purposes of the Mosquito sample application, the overlay surface is no longer needed. If you still need the overlay surface for later, you could simply hide the overlay without releasing it, then redisplay it whenever you require.