A logical palette is stored in the memory and belongs to a DIB (Device Independent Bitmap). If there is a logical palette somewhere in your memory, it was probably loaded from a .bmp-file (which contains a DIB) or maybe just created for a new image (this happens every time, you create a new 256-color bitmap in an image-editing program). The only limit for the number of logical palettes is the amount of memory available.
The system palette (or hardware palette) contains 236 colors of the palette(s) with the highest priority (explained below), as well as 20 reserved entries, that windows uses to draw windows, buttons,... Every DDB (Device Dependent Bitmap) that is currently displayed has to use the colors of the system palette. There only exists the system palette, which is managed by Windows itself. The programmer only has in so far influence on the system palette as he tells Windows which (logical) palette to insert into the system palette.
A special form of a logical palette is an identity palette. An identity palette contains the 20 reserved colors at the same positions as the system palette does (details). In the other 236 entries the identity palette contains the colors that its associated DIB uses. Using an identity palette has the advantage that the reserved colors con also be used in the bitmap. However, using an identity palette only makes sense if the bitmap is displayed in 256-colors display mode because in this mode there are only 236 bitmap-specific colors possible. When a bitmap will be displayed in truecolor mode then it will probably be wiser to use a palette with 256 bitmap-specific colors.
Palette-Management
Normally there are many logical palettes stored in the memory. Every logical palette belongs to a special bitmap or
window. To provide the greatest reconciliation possible between all those different windows, bitmaps and palettes,
there is this important rule: The window which currently has the focus also has the
privilege to be the first to map colors into the system palette. If this window doesn't use a palette or doesn't fill all the
236 entries available than this privilege is passed to the next window along the z-axis (the window which is the
second from top). This process is repeated as long as either the system palette is filled or every window had its
chance to map colors into the system palette. For every logical palette mapped to the system palette a
foreground-mapping is created. This foreground-mapping is nothing more than a table which can be used to
convert color indexes from the logical palette it belongs to into the color indexes of the (current) system palette. The
foreground-mapping provides the index in the system palette for every entry in the logical palette. For the windows
that couldn't map their colors to the system palette, the nearest matching colors in the system palette are assigned
to the colors in the logical palette.
If a DIB (which pixel values point to entries of its logical palette) is displayed on the screen, it must be converted to a
DDB (which pixel values point to entries of the current system palette). The foreground-mapping is used to convert the
pixel values. Note that this only applies to the 256-colors display mode. In truecolor display mode the pixel values do
not have to be converted because they can be displayed using their literal RGB values and not pointers to the system
palette.
Palette-Management API functions
There are not very much API palette functions, however four of them are rather important: AnimatePalette (see the text
Palette Animation for further discussion of AnimatePalette), CreatePalette, SelectPalette and RealizePalette.
For further explanation of the following functions see your API documentation. The function CreatePalette is used to create a logical palette from a LOGPALETTE structure. The return value is the handle of the logical palette.
HPALETTE CreatePalette(lplogpal)
HPALETTE SelectPalette(hdc, hpal, fPalBack)
UINT RealizePalette(HDC hdc)