HPALETTE SelectPalette(hdc, hpal, fPalBack) | |||||
HDC hdc; | /* handle of device context | */ | |||
HPALETTE hpal; | /* handle of palette, */ | ||||
BOOL fPalBack; | /* flag for forcing palette to background | */ |
The SelectPalette function selects the specified logical palette into the given device context. The selected palette replaces the previous palette for that device context.
hdc
Identifies the device context.
hpal
Identifies the logical palette to be selected.
fPalBack
Specifies whether the logical palette is always to be a background palette. If this parameter is nonzero, the selected palette is always a background palette. If this parameter is zero and the device context is attached to a window, the logical palette is a foreground palette when the window has the input focus. (The device context is attached to a window if it was obtained by using the GetDC function or if the window-class style is CS_OWNDC.)
The return value is the handle of the previous logical palette for the given device context, if the function is successful. Otherwise, it is NULL.
An application can select a logical palette into more than one device context. However, changes to a logical palette will affect all device contexts for which it is selected. If an application selects a palette into more than one device context, the device contexts must all belong to the same physical device.
The following example calls the SelectPalette function to select a logical palette into a device context and then calls the RealizePalette function to change the palette size:
HPALETTE hpal, hPalPrevious;
hdc = GetDC(hwnd);
hPalPrevious = SelectPalette(hdc, hpal, FALSE);
if (RealizePalette(hdc) == NULL)
MessageBox(hwnd, "Can't realize palette", "Error", MB_OK);
ReleaseDC(hwnd, hdc);