Un extracto de un tutorial:
3. Losing Surfaces
One very important area of robustness that the code samples above ignored is what happens if the user switches away from a fullscreen DirectDraw app to some other app running in the system. First of all, your code needs to handle the WM_ACTIVATEAPP message and set a flag when your app goes inactive. In the idle section of your PeekMessage loop, check this flag, and don't try to update your display when you're not active.
But the real issue is that once you switch to another app, you have left the DirectDraw environment and allowed GDI to become active. GDI is oblivious to DirectDraw, and will overwrite the areas of display memory in use by your DirectDraw surfaces. This means that your bitmaps get wiped out and will need to be reloaded. Fortunately, when you call a function that operates on a surface, such as Flip() or BltFast(), DirectDraw will return an error of DDERR_SURFACELOST to let you know if the surface was lost. So, your code has to check for this error and reload the bitmaps into the surfaces if this error occurs.
ddrval = lpDDSPrimary->Blt( &rcRectDest, lpDDSBack, &rcRectSrc, DDBLT_WAIT, NULL);
if( ddrval == DDERR_SURFACELOST )
{
ddrval = restoreAll();
}
ddrval = lpDDSPrimary->Flip( NULL, DDFLIP_WAIT);
if( ddrval == DDERR_SURFACELOST )
{
ddrval = restoreAll();
}
:
:
void restoreAll()
{
// for each surface your app has created you should do the following:
ddrval = lpMyDDSurface->Restore(); // this reattaches the video memory to the surface
if( ddrval == DD_OK )
{
lpTempDDS ->DDReLoadBitmap(); // this will be the same as the function above
// that was originally used to load the bitmap
// with the exception that the surface is already
// created and ready to go
}
}
Bueno, básicamente cuendo el DDraw avisa si se perdió la superficie hay que aplicar un "restore" a la superficie y volver a recuperarla.
En mi caso uso siempre modo cooperativo, por lo menos hasta que termine mi juego.
¿Por que:?
1.- Cuando pasa algo "malo" en modo exclusivo (no cooperativo) y no preveiste el caso la pantalla no se restaura y queda toda negra y no queda otra que reiniciar.
2.- En modo cooperativo nunca pierdes superficies:)
3.- Aunque si hay que diseñar el juego para que pueda ser ejecutado en modo exclusivo y se pueda implementar la recuperación de superficies sin mayores problemas, pienso que esa parte de la implementación se la debe hacer al final por comodidad ya que básicamente lo único que se gana es optimización (y no mucha la verdad) al utilizar el flip real. Digo esto especialmente por el punto 1.