After your application has selected its palette into a device context, it must realize the palette before using it, as follows:
RealizePalette
(hDC);
When your application calls the RealizePalette function, Windows compares the system palette with your logical palette and matches identical colors. If there is room in the system palette, Windows then maps unmatched colors in the logical palette to the system palette. Finally, if there are unmatched colors that it could not map to the system palette, Windows matches the remaining colors to the nearest color in the system palette.