GetNearestPaletteIndex

3.0

  UINT GetNearestPaletteIndex(hpal, clrref)    
  HPALETTE hpal; /* handle of palette, */  
  COLORREF clrref; /* color to match, */  

The GetNearestPaletteIndex function retrieves the index of the logical-palette entry that best matches the specified color value.

Parameters

hpal

Identifies the logical palette.

clrref

Specifies the color to be matched.

Return Value

The return value is the index of the logical-palette entry whose corresponding color best matches the specified color.

Example

The following example uses the GetNearestPaletteIndex function to retrieve a color index from a palette. It then creates a brush with that retrieved color by using the PALETTEINDEX macro in a call to the CreateSolidBrush function.

WORD nColor;
HPALETTE hpal;
DWORD dwBrushColors[8][8];
HBRUSH hbr;
int x, y;
    .
    . /* Initialize the array of brush colors. */
    .
nColor = GetNearestPaletteIndex(hpal, dwBrushColors[x][y]);
hbr = CreateSolidBrush(PALETTEINDEX(nColor));

    .
    . /* Use the brush handle. */
    .
DeleteObject(hbr);

See Also

CreateSolidBrush, GetNearestColor, GetPaletteEntries, GetSystemPaletteEntries