HPALETTE CreatePalette(lplgpl) | |||||
const LOGPALETTE FAR* lplgpl; | /* address of LOGPALETTE structure | */ |
The CreatePalette function creates a logical color palette.
lplgpl
Points to a LOGPALETTE structure that contains information about the colors in the logical palette. The LOGPALETTE structure has the following form:
typedef struct tagLOGPALETTE { /* lgpl */
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[1];
} LOGPALETTE;
For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.
The return value is the handle of the logical palette if the function is successful. Otherwise, it is NULL.
When it has finished using a palette created by CreatePalette, an application should remove the palette by using the DeleteObject function.
The following example initializes a LOGPALETTE structure and an array of PALETTEENTRY structures, and then uses the CreatePalette function to retrieve a handle of a logical palette:
#define NUMENTRIES 128
HPALETTE hpal;
PALETTEENTRY ape[NUMENTRIES];
plgpl = (LOGPALETTE*) LocalAlloc(LPTR,
sizeof(LOGPALETTE) + cColors * sizeof(PALETTEENTRY));
plgpl->palNumEntries = cColors;
plgpl->palVersion = 0x300;
for (i = 0, red = 0, green = 127, blue = 127; i < NUMENTRIES;
i++, red += 1, green += 1, blue += 1) {
ape[i].peRed =
plgpl->palPalEntry[i].peRed = LOBYTE(red);
ape[i].peGreen =
plgpl->palPalEntry[i].peGreen = LOBYTE(green);
ape[i].peBlue =
plgpl->palPalEntry[i].peBlue = LOBYTE(blue);
ape[i].peFlags =
plgpl->palPalEntry[i].peFlags = PC_RESERVED;
}
hpal = CreatePalette(plgpl);
LocalFree((HLOCAL) plgpl);
.
. /* Use the palette handle. */
.
DeleteObject(hpal);