INF: Background, Foreground, and System Palette Management

ID Number: Q72386

3.00 3.10

WINDOWS

Summary:

On a device that supports the Windows palette management functions, an

application can create a logical palette, select the palette into a

device context (DC), and realize the palette. Realizing a logical

palette maps its colors to the system (hardware) color palette. The

GetDeviceCaps function is available to inform an application whether

the device is capable of supporting palette management functions and,

if so, the size of its system palette. This article discusses the

different types of logical palettes and the effect of each on the

system palette when a logical palette is realized.

More Information:

When a logical palette is selected into a DC, it can be selected as

either a foreground or a background palette. Setting the

bForceBackground parameter of the SelectPalette function to TRUE

selects the palette as a background palette. If this parameter is

FALSE, the palette may be selected as a foreground palette. A palette

will be selected as a foreground palette only if the DC into which the

palette is selected is one of the five cached DCs managed by the

GetDC function and the DC is retrieved on behalf of the active

window. If the DC is returned by the CreateDC or

CreateCompatibleDC functions, or if the window is not the active

window, the palette will be forced into the background.

The status as a foreground or a background palette affects how the

colors in the logical palette are mapped into the system palette when

the logical palette is realized.

When a foreground palette is realized, every entry in the system

palette that can be modified by applications is accessible to the

logical palette. Logical palette entries are mapped into the system

palette starting at the first available entry. A logical palette entry

that exactly matches a reserved system palette entry is mapped to that

system entry therefore it does not consume a separate palette slot. If

the logical palette has more entries than available slots in the

system palette, the available slots are filled, in order, from the

logical palette. The remaining logical palette entries are mapped to

the closest colors already present in the system palette. There is one

exception to this rule: if a logical palette entry is marked with the

PC_RESERVED flag, no colors will be mapped to that entry. If all

available system palette entries are reserved, additional colors will

not be mapped to any entry and will be displayed as black on the

screen.

A palette entry marked as PC_NOCOLLAPSE will always take a separate

slot if available, just as for PC_RESERVED. Unlike a PC_RESERVED

color, if no slots are available, it will map to the nearest color,

and other colors may map onto it.

The first available entry in the system palette is the first palette

entry not marked as used. For example, assume a device with 256

palette entries, 20 of which are reserved for the system. An

application realizes a palette of 36 colors on this device, therefore

the first 36 entries are marked used. Another application realizes a

100-entry palette, therefore the next 100 entries are marked used.

If a third application receives the input focus and realizes a

foreground palette with 236 entries, the remainder of the system

palette will be filled. The remaining colors are mapped into the

first 136 entries.

When a background palette is realized, any empty positions in the

system palette are filled. Any colors that remain are mapped to the

closest color in the system palette. A background palette entry cannot

overlay a foreground entry in the system palette; however, a

foreground palette entry can overlay a background entry in the system

palette.

Additional reference words: 3.00 3.10 3.x