// VARIABLES
// The DirectDraw object, used to create the Primary surface and
// access the DirectDraw functions.
LPDIRECTDRAW7 lpDD = NULL;

 // The primary DDraw surface, this represents the screen.
LPDIRECTDRAWSURFACE7  lpDDSPrimary = NULL;

// The back buffer, things are blitted onto this then flipped to
// the Primary surface.
LPDIRECTDRAWSURFACE7 lpDDSBack = NULL;

// A surface description structure, used to describe the
// primary and back surfaces for the CreateSurface() function.
DDSURFACEDESC2 ddsd;

// A surface capabilities structure, used to tell
// CreateSurface() what kind of surface to create.
DDSCAPS2 ddscaps;

// GET DIRECT DRAW OBJECT
// Create the DDraw7 object.
if ( FAILED( DirectDrawCreateEx( NULL, ( LPVOID* )&lpDD, IID_IDirectDraw7, NULL ) )
    return FALSE;

// SET DISPLAY MODE
// Get exclusive mode. Be sure to allow people to press
// Alt-Ctrl-Del ( DDSCL_ALLOWREBOOT ).

if ( FAILED( lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT ) ) )
    return FALSE;

// Set the display mode to 800x600 with 16 bits per pixel.
if ( FAILED( lpDD->SetDisplayMode( 800, 600, 16, 0, 0 ) ) )
    return FALSE;

// CREATE PRIMARY SURFACE
// Create the primary surface with 1 back buffer. Make it
// the height and width of the screen.
// First, zero the memory used by the ddsd structure.
// If you don't do this, it may have some random data that
// might mess up CreateSurface().
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );

// DDSD_CAPS makes CreateSurface() check the
// ddsd.ddsCaps.dwCaps value. DDS_BACKBUFFERCOUNT makes it
// check the ddsd.dwBackBufferCount value.
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// Make it the primary surface that can be flipped.
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

// Give it one back buffer.
ddsd.dwBackBufferCount = 1;

// Make it the same size as the screen.
ddsd.dwWidth = 800;
ddsd.dwHeight = 600;

// Create the primary surface using the description in
// ddsd.
if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
    return FALSE;

// CREATE BACK BUFFER
if ( FAILED( lpDDSPrimary->GetAttachedSurface( &ddscaps,
             &lpDDSBack ) ) )
    return FALSE;