void TransparentStretchBlt(HDC hDC, LONG left, LONG top, LONG width, LONG height, HBITMAP hBitmap, LONG bmLeft, LONG bmTop, LONG bmWidth, LONG bmHeight, COLORREF colorMask) { HDC hMemDC, hStretchDC, hMaskDC; HBITMAP hStretchBm, hMaskBm, hOldMemBm, hOldStretchBm, hOldMaskBm; COLORREF oldColor; // Create the memory DC's. hMemDC = CreateCompatibleDC(hDC); hStretchDC = CreateCompatibleDC(hDC); hMaskDC = CreateCompatibleDC(hDC); // Create the bitmaps needed for the memory DC's. hStretchBm = CreateCompatibleBitmap(hDC, width, height); hMaskBm = CreateBitmap(width, height, 1, 1, NULL); // Select the bitmaps into the memory DC's. hOldMemBm = (HBITMAP)SelectObject(hMemDC, hBitmap); hOldStretchBm = (HBITMAP)SelectObject(hStretchDC, hStretchBm); hOldMaskBm = (HBITMAP)SelectObject(hMaskDC, hMaskBm); // StretchBlt to a colored DC. StretchBlt(hStretchDC, 0, 0, width, height, hMemDC, bmLeft, bmTop, bmWidth, bmHeight, SRCCOPY); // BitBlt to a monochrome DC. oldColor = SetBkColor(hStretchDC, colorMask); BitBlt(hMaskDC, 0, 0, width, height, hStretchDC, 0, 0, SRCCOPY); SetBkColor(hStretchDC, oldColor); // Transparent BitBlt technique. BitBlt(hDC, left, top, width, height, hMaskDC, 0, 0, SRCAND); BitBlt(hDC, left, top, width, height, hStretchDC, 0, 0, SRCPAINT); // Restore the memory DC's. SelectObject(hMemDC, hOldMemBm); SelectObject(hStretchDC, hOldStretchBm); SelectObject(hMaskDC, hOldMaskBm); // Delete the allocated bitmaps. DeleteObject(hStretchBm); DeleteObject(hMaskBm); // Delete the allocated memory DC's. DeleteDC(hMemDC); DeleteDC(hStretchDC); DeleteDC(hMaskDC); }