Animating a Palette

The following example animates a palette by using the DrawDibRealize, DrawDibChangePalette, and DrawDibDraw functions.

You can change the colors of a bitmap by using the DrawDibBegin function in combination with DrawDibChangePalette. First, to allow palette changes, specify the DDF_ANIMATE flag in the call to DrawDibBegin. Second, set the color table values from the palette entries by using DrawDibChangePalette.

For example, if lppe is an address of the PALETTEENTRY array containing the new colors, and lpbi is the LPBITMAPINFOHEADER structure used in DrawDibBegin or DrawDibDraw, the following fragment updates the DIB color table.

hdc = GetDC(hwnd); 
DrawDibBegin(hdd, ....., DDF_ANIMATE); 
DrawDibRealize(hdd, hdc, fBackground); 
DrawDibDraw(hdd, hdc, ...., DDF_SAME_DRAW|DDF_SAME_HDC); 
 
// Call to change color. 
DrawDibChangePalette(hDD, iStart, iLen, lppe); 
. 
. 
. 
ReleaseDC(hwnd, hdc);