+ if (IsKindOf(CLASSINFO(wxPrinterDC)))
+ {
+ // If we are printing source colours are screen colours
+ // not printer colours and so we need copy the bitmap
+ // pixel by pixel.
+ RECT rect;
+ HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
+ HDC dc_src = (HDC) source->m_hDC;
+
+ ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
+ for (int x = 0; x < width; x++)
+ {
+ for (int y = 0; y < height; y++)
+ {
+ COLORREF cref = ::GetPixel(dc_mask, x, y);
+ if (cref)
+ {
+ HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y));
+ rect.left = xdest1 + x; rect.right = rect.left + 1;
+ rect.top = ydest1 + y; rect.bottom = rect.top + 1;
+ ::FillRect(GetHdc(), &rect, brush);
+ ::DeleteObject(brush);
+ }
+ }
+ }
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+ }
+ else
+ {
+ // create a temp buffer bitmap and DCs to access it and the mask
+ HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC);
+ HDC dc_buffer = ::CreateCompatibleDC(GetHdc());
+ HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
+ ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap());
+ ::SelectObject(dc_buffer, buffer_bmap);
+
+ // copy dest to buffer
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ GetHdc(), xdest1, ydest1, SRCCOPY);
+
+ // copy src to buffer using selected raster op
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ (HDC) source->m_hDC, xsrc1, ysrc1, dwRop);
+
+ // set masked area in buffer to BLACK (pixel value 0)
+ COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255));
+ COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0));
+ ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
+ dc_mask, xsrc1, ysrc1, SRCAND);
+
+ // set unmasked area in dest to BLACK
+ ::SetBkColor(GetHdc(), RGB(0, 0, 0));
+ ::SetTextColor(GetHdc(), RGB(255, 255, 255));
+ ::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ dc_mask, xsrc1, ysrc1, SRCAND);
+ ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values
+ ::SetTextColor(GetHdc(), prevCol);
+
+ // OR buffer to dest
+ success = (::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height,
+ dc_buffer, 0, 0, SRCPAINT) != 0);
+
+ // tidy up temporary DCs and bitmap
+ ::SelectObject(dc_mask, 0);
+ ::DeleteDC(dc_mask);
+ ::SelectObject(dc_buffer, 0);
+ ::DeleteDC(dc_buffer);
+ ::DeleteObject(buffer_bmap);
+ }
+ }
+ }
+ else
+ {