Share via


How to use DirectDraw (Windows Embedded CE 6.0)

1/6/2010

This topic includes code snippets that initialize DirectDraw and demonstrate simple drawing.

Initializing DirectDraw

This code example initializes DirectDraw.

#include <ddraw.h>

HRESULT hr;
IDirectDraw * pDD = NULL;
IDirectDrawSurface * pDDSPrimary = NULL;
DDSURFACEDESC ddsd;

hr = DirectDrawCreate(NULL, &pDD, NULL);
hr = pDD->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN);
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
hr = pDD->CreateSurface(&ddsd, &pDDSPrimary, NULL);

Initializing DirectDraw

This code example sets a pixel at the address x=57, y=97 to the color red.

#include <ddraw.h>

HRESULT hr;
hr = pDDSPrimary->Lock(NULL, &ddsd, DDLOCK_WAITNOTBUSY, NULL);
// Set pixel 57, 97 to Red (assuming RGB565 pixel fmt)
int x = 57;
int y = 97;
BYTE * pPixelOffset = (BYTE*)ddsd.lpSurface 
    + x * ddsd.lXPitch
    + y * ddsd.lPitch;
*(WORD*)pPixelOffset = 0xf800;
hr = pDDSPrimary->Unlock(NULL);

See Also

Concepts

Getting Started with DirectDraw