As you would any other GDI object, you must select the palette into the device context in which it is to be used. The usual way to do this is by calling the SelectObject function. However, because SelectObject does not recognize a palette object, you must instead call SelectPalette to select the palette into the device context:
hDC = GetDC(hWnd);
SelectPalette(hDC, hPal, 0);
These statements associate the palette with the device context so that any reference to a palette (such as a palette index passed to a GDI function instead of a color) will be to the selected palette.
To delete a logical-palette object, you use the DeleteObject function.
Since the palette is independent of any particular device context, several windows can share it. However, Windows does not make a copy of the palette object when an application selects the palette into a device context; consequently, any change to the palette affects all device contexts using the same palette. Also, if an application selects a palette object into more than one device context, the device contexts must all belong to the same physical device (such as a screen or printer). In other respects, however, a palette object is like other Windows objects.