|
发表于 2011-6-5 10:17:00
|
显示全部楼层
Re:DirectDraw,求助! 使用自定义的surfaceMemory创建Surface时,返
// For this example, g_lpDD is a valid IDirectDraw7 interface pointer.
#define WIDTH 64 // in pixels
#define HEIGHT 64
#define DEPTH 3 // in bytes (3bytes == 24 bits)
HRESULT hr;
LPVOID lpSurface = NULL;
HLOCAL hMemHandle = NULL;
DDSURFACEDESC2 ddsd2;
LPDIRECTDRAWSURFACE7 lpDDS;
// Allocate memory for a 64 by 64, 24-bit per pixel buffer.
// REMEMBER: The application is responsible for freeing this
// buffer when it is no longer needed.
if (lpSurface = malloc((size_t)WIDTH*HEIGHT*DEPTH))
ZeroMemory(lpSurface, (DWORD)WIDTH*HEIGHT*DEPTH);
else
return DDERR_OUTOFMEMORY;
// Initialize the surface description.
ZeroMemory(&ddsd2, sizeof(DDSURFACEDESC2));
ZeroMemory(&ddsd2.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
ddsd2.dwSize = sizeof(ddsd2);
ddsd2.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
DDSCAPS_SYSTEMMEMORY;
ddsd2.dwWidth = WIDTH;
ddsd2.dwHeight= HEIGHT;
ddsd2.lPitch = (LONG)DEPTH * WIDTH;
ddsd2.lpSurface = lpSurface;
// Set up the pixel format for 24-bit RGB (8-8-8).
ddsd2.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd2.ddpfPixelFormat.dwFlags= DDPF_RGB;
ddsd2.ddpfPixelFormat.dwRGBBitCount = (DWORD)DEPTH*8;
ddsd2.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
ddsd2.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
ddsd2.ddpfPixelFormat.dwBBitMask = 0x000000FF;
// Create the surface
hr = g_lpDD->CreateSurface(&ddsd2, &lpDDS, NULL);
return hr;
sdk里面的例子 |
|