+// Get the bitmap
+wxBitmap wxImageList::GetBitmap(int index) const
+{
+ int bmp_width = 0, bmp_height = 0;
+ GetSize(index, bmp_width, bmp_height);
+
+ wxBitmap bitmap(bmp_width, bmp_height);
+ wxMemoryDC dc;
+ dc.SelectObject(bitmap);
+
+ // draw it the first time to find a suitable mask colour
+ ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
+ dc.SelectObject(wxNullBitmap);
+
+ // find the suitable mask colour
+ wxImage image = bitmap.ConvertToImage();
+ unsigned char r = 0, g = 0, b = 0;
+ image.FindFirstUnusedColour(&r, &g, &b);
+
+ // redraw whole image and bitmap in the mask colour
+ image.Create(bmp_width, bmp_height);
+ image.Replace(0, 0, 0, r, g, b);
+ bitmap = wxBitmap(image);
+
+ // redraw icon over the mask colour to actually draw it
+ dc.SelectObject(bitmap);
+ ((wxImageList*)this)->Draw(index, dc, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT);
+ dc.SelectObject(wxNullBitmap);
+
+ // get the image, set the mask colour and convert back to get transparent bitmap
+ image = bitmap.ConvertToImage();
+ image.SetMaskColour(r, g, b);
+ bitmap = wxBitmap(image);
+
+ return bitmap;
+}
+
+// Get the icon
+wxIcon wxImageList::GetIcon(int index) const
+{
+ HICON hIcon = ImageList_ExtractIcon(0, GetHImageList(), index);
+ if (hIcon)
+ {
+ wxIcon icon;
+ icon.SetHICON((WXHICON)hIcon);
+
+ int iconW, iconH;
+ GetSize(index, iconW, iconH);
+ icon.SetSize(iconW, iconH);
+
+ return icon;
+ }
+ else
+ return wxNullIcon;
+}
+
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
+static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask)
+{
+ HBITMAP hbmpMask;
+ wxMask *pMask;
+ bool deleteMask = false;
+
+ if ( mask.Ok() )
+ {
+ hbmpMask = GetHbitmapOf(mask);
+ pMask = NULL;
+ }
+ else
+ {
+ pMask = bitmap.GetMask();
+ if ( !pMask )
+ {
+ // use the light grey count as transparent: the trouble here is
+ // that the light grey might have been changed by Windows behind
+ // our back, so use the standard colour map to get its real value
+ wxCOLORMAP *cmap = wxGetStdColourMap();
+ wxColour col;
+ wxRGBToColour(col, cmap[wxSTD_COL_BTNFACE].from);
+
+ pMask = new wxMask(bitmap, col);
+
+ deleteMask = true;
+ }
+
+ hbmpMask = (HBITMAP)pMask->GetMaskBitmap();
+ }
+
+ // windows mask convention is opposite to the wxWidgets one
+ HBITMAP hbmpMaskInv = wxInvertMask(hbmpMask);
+
+ if ( deleteMask )
+ {
+ delete pMask;
+ }
+
+ return hbmpMaskInv;
+}
+
+#endif // Win95