Managing Palettes in a WinG Application

DOS executes only one application at a time, so every DOS application has the freedom to modify the hardware palette on palette devices (such as VGA) without interfering with other active applications. In the multitasking Windows environment, applications must modify the palette through the Palette Manager to ensure friendly interoperability of applications.

The most common programming error in palettized Windows applications stems from the system selecting the stock system palette into devices acquired through GetDC or through a WM_PAINT message. The application must call SelectPalette and RealizePalette to set and activate a palette in these DCs, and the palette information survives in the DC only in the time between GetDC and ReleaseDC calls.

The following code snippet will result in an image mapped to the static colors:

HDC hdc = GetDC(hwnd);

SelectPalette(hdc, hpal, FALSE);

RealizePalette(hdc);

ReleaseDC(hwnd, hdc);// Palette information lost!!

...

hdc = GetDC(hwnd);// DC with stock palette selected!!

BitBlt(hdc, x,y,width,height, source, 0,0, SRCCOPY);

ReleaseDC(hwnd, hdc);

Ron Gery's article "The Palette Manager: How and Why" (Microsoft Technical Article, 23 March 1992) describes the mechanisms of the Palette Manager in depth. The following articles discuss optimizing Palette Manager use in WinG applications.

Using an Identity Palette

Palette Animation With WinG

Accessing a Full Palette Using SYSPAL_NOSTATIC