- // 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);