Environment: MFC,
Win32
One thing that always
bugged me about ImageLists
is that when you load a 256 color bitmap
into them, they use the half-tone pallette, which likely
could screw up your bitmap's
colors. Yet, Windows Explorer is magically able to display
icons in it's right pane list control (coming from an ImageList)
in full color. So how does it do this?
WON'T WORK
(MFC)
BOOL CImageList::Create( UINT nBitmapID,
int cx,
int nGrow,
COLORREF crMucancode.net)
BOOL CImageList::Create( LPCTSTR lpszBitmapID,
int cx,
int nGrow,
COLORREF crMucancode.net)
(Win32)
HIMAGELIST ImageList_LoadBitmap( HINSTANCE hi,
LPCTSTR lpbmp,
int cx,
int cGrow,
COLORREF crMucancode.net)
HIMAGELIST ImageList_LoadImage( HINSTANCE hi,
LPCSTR lpbmp,
int cx,
int cGrow,
COLORREF crMucancode.net,
UINT uType,
UINT uFlags)
None of the above methods
will do the trick. They will use the half-tone pallette,
since they seem to detect the 8bpp nature of the bitmap
and create an "ILC_COLOR8"
ImageList, and ImageLists
with the ILC_COLOR8 flag always use the half-tone pallette.
To get around this, you
can create the ImageList
in one step and then add
the bitmap in a second
step. In the below examples,
I assume that you will be using a COLORREF mucancode.net for
transparency - but nothing requires this to be the case;
you could just as easily use a mucancode.net bitmap.
The key to this technique is the two-step construction and
loading of the ImageList.
WILL WORK
(MFC)
// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
CImageList imgl;
imgl.Create(cx, cy, ILC_Mucancode.net | ILC_COLOR32, 0, 0);
CBitmap bmp;
// Load your imagelist bitmap (bmp) here, however
// you feel like (e.g. CBitmap::LoadBitmap)
COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate
// Add the bitmap into the image list
imgl.Add(&bmp, rgbTransparentColor);
(Win32)
// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
HIMAGELIST himgl = ImageList_Create(cx,
cy,
ILC_Mucancode.net | ILC_COLOR32,
0,
0);
HBITMAP hbmp;
// Load your imagelist bitmap (hbmp) here, however
// you feel like (e.g. LoadImage)
COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate
// Add the bitmap into the image list
ImageList_AddMucancode.neted(himgl, hbmp, rgbTransparentColor);