Use oneThe CImageList control is used to load bitmaps for TREE controls. Other colors are normally orange and yellow.
You can only use20 colors (orange is not included); of course, you can also use the following method to load bitmap resources without being limited by the number of colors.
HBITMAP LoadResourceBitmap (HINSTANCE hInstance, LPSTR lpString,
Hpalette far * lphPalette)
{
HRSRC hRsrc;
HGLOBAL hGlobal;
HBITMAP hBitmapFinal = NULL;
LPBITMAPINFOHEADER lpbi;
HDC hdc;
Int iNumColors;
If (hRsrc =: FindResource (hInstance, lpString, RT_BITMAP ))
{
HGlobal =: LoadResource (hInstance, hRsrc );
Lpbi = (LPBITMAPINFOHEADER) LockResource (hGlobal );
Hdc =: GetDC (NULL );
* LphPalette = CreateDIBPalette (LPBITMAPINFO) lpbi, & iNumColors );
If (* lphPalette)
{
: SelectPalette (hdc, * lphPalette, FALSE );
: RealizePalette (hdc );
}
HBitmapFinal =: CreateDIBitmap (hdc,
(LPBITMAPINFOHEADER) lpbi,
(LONG) CBM_INIT,
(LPSTR) lpbi + lpbi-> biSize + iNumColors * sizeof (RGBQUAD ),
(LPBITMAPINFO) lpbi,
DIB_RGB_COLORS );
: ReleaseDC (NULL, hdc );
//: UnlockResource (hGlobal );
//: FreeResource (hGlobal );
}
Return (hBitmapFinal );
}
// Internally used by LoadResourceBitmap
HPALETTE CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
{
LPBITMAPINFOHEADER lpbi;
LPLOGPALETTE lpPal;
HANDLE hLogPal;
HPALETTE hPal = NULL;
Int I;
Lpbi = (LPBITMAPINFOHEADER) lpbmi;
If (lpbi-> biBitCount <= 8)
* LpiNumColors = (1 <lpbi-> biBitCount );
Else
* LpiNumColors = 0; // No palette needed for 24 BPP DIB
If (lpbi-> biClrUsed> 0)
* LpiNumColors = lpbi-> biClrUsed; // Use biClrUsed
If (* lpiNumColors)
{
HLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) +
Sizeof (PALETTEENTRY) * (* lpiNumColors ));
LpPal = (LPLOGPALETTE) GlobalLock (hLogPal );
LpPal-> palVersion = 0x300;
LpPal-> palNumEntries = * lpiNumColors;
For (I = 0; I <* lpiNumColors; I ++)
{
LpPal-> pal
PalEntry [I].
PeRed = lpbmi-> bmiColors [I]. rgbRed;
LpPal-> palP