Creating a Palette in Windowed Mode
The following example illustrates how to create a DirectDraw palette in nonexclusive (windowed) mode. In order for your palette to work correctly, it is vital that you set up every one of the 256 entries in the PALETTEENTRY structure that you submit to the IDirectDraw4::CreatePalette method.
LPDIRECTDRAW4 lpDD; // Assumed to be initialized previously
PALETTEENTRY pPaletteEntry[256];
int index;
HRESULT ddrval;
LPDIRECTDRAWPALETTE2 lpDDPal;
// First set up the Windows static entries.
for (index = 0; index < 10 ; index++)
{
// The first 10 static entries:
pPaletteEntry[index].peFlags = PC_EXPLICIT;
pPaletteEntry[index].peRed = index;
pPaletteEntry[index].peGreen = 0;
pPaletteEntry[index].peBlue = 0;
// The last 10 static entries:
pPaletteEntry[index+246].peFlags = PC_EXPLICIT;
pPaletteEntry[index+246].peRed = index+246;
pPaletteEntry[index+246].peGreen = 0;
pPaletteEntry[index+246].peBlue = 0;
}
// Now set up private entries. In this example, the first 16
// available entries are animated.
for (index = 10; index < 26; index ++)
{
pPaletteEntry[index].peFlags = PC_NOCOLLAPSE|PC_RESERVED;
pPaletteEntry[index].peRed = 255;
pPaletteEntry[index].peGreen = 64;
pPaletteEntry[index].peBlue = 32;
}
// Now set up the rest, the nonanimated entries.
for (; index < 246; index ++) // Index is set up by previous for loop
{
pPaletteEntry[index].peFlags = PC_NOCOLLAPSE;
pPaletteEntry[index].peRed = 25;
pPaletteEntry[index].peGreen = 6;
pPaletteEntry[index].peBlue = 63;
}
// All 256 entries are filled. Create the palette.
ddrval = lpDD->CreatePalette(DDPCAPS_8BIT, pPaletteEntry,
&lpDDPal,NULL);
Last updated on Thursday, April 08, 2004
© 1992-2003 Microsoft Corporation. All rights reserved.