static HBITMAP GetMaskForImage(const wxBitmap& bitmap, const wxBitmap& mask)
{
HBITMAP hbmpMask;
- wxBitmap *bmpMask = NULL;
+ wxMask *pMask;
+ bool deleteMask = FALSE;
if ( mask.Ok() )
{
hbmpMask = GetHbitmapOf(mask);
+ pMask = NULL;
}
else
{
- wxMask *pMask = bitmap.GetMask();
- if ( pMask )
+ pMask = bitmap.GetMask();
+ if ( !pMask )
{
- hbmpMask = (HBITMAP)pMask->GetMaskBitmap();
- }
- else
- {
- // create a non transparent mask - apparently, this is needed under
- // Win9x (it doesn't behave correctly if it's passed 0 mask)
- bmpMask = new wxBitmap(bitmap.GetWidth(), bitmap.GetHeight(), 1);
+ // 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);
- wxMemoryDC dcMem;
- dcMem.SelectObject(*bmpMask);
- dcMem.Clear();
- dcMem.SelectObject(wxNullBitmap);
+ pMask = new wxMask(bitmap, col);
- hbmpMask = GetHbitmapOf(*bmpMask);
+ deleteMask = TRUE;
}
+
+ hbmpMask = (HBITMAP)pMask->GetMaskBitmap();
}
// windows mask convention is opposite to the wxWindows one
HBITMAP hbmpMaskInv = wxInvertMask(hbmpMask);
- delete bmpMask;
+
+ if ( deleteMask )
+ {
+ delete pMask;
+ }
return hbmpMaskInv;
}