- if ( ::MaskBlt(GetHdc(), xdest, ydest,
- (int)width, (int)height,
- GetHdcOf(*source), xsrc, ysrc,
- (HBITMAP) mask->GetMaskBitmap(),
- 0, 0, MAKEROP4(SRCCOPY, PATCOPY)) != 0 )
- {
- // Success
- success = TRUE;
- }
- else
+ HBITMAP hbmpMask = wxInvertMask((HBITMAP)mask->GetMaskBitmap());
+
+ // we want the part of the image corresponding to the mask to be
+ // transparent, i.e. do PATCOPY there and apply dwRop elsewhere
+ const wxColour& colBg = m_backgroundBrush.GetColour();
+ HBRUSH hbrBg = (HBRUSH)::CreateSolidBrush(wxColourToRGB(colBg));
+ HBRUSH hbrOld = (HBRUSH)::SelectObject(GetHdc(), hbrBg);
+
+ success = ::MaskBlt(GetHdc(), xdest, ydest, width, height,
+ GetHdcOf(*source), xsrc, ysrc,
+ hbmpMask, 0, 0,
+ MAKEROP4(PATCOPY, dwRop)) != 0;
+
+ (void)::SelectObject(GetHdc(), hbrOld);
+ ::DeleteObject(hbrOld);
+ ::DeleteObject(hbmpMask);
+
+ if ( !success )