void TransparentBlt(CDC *pDestDC, int nXDest, int nYDest, int nWidth, int nHeight, CBitmap * pBitmap, int nXsrc, int nYsrc, COLORREF clr)
{
CDC maskDC, ImageDC;
maskDC.CreateCompatibleDC(pDestDC);
ImageDC.CreateCompatibleDC(pDestDC);
CBitmap maskBMP;
maskBMP.CreateBitmap(nWidth, nHeight, 1, 1, NULL);//创建单色掩码位图
CBitmap *pOldBMP = ImageDC.SelectObject(pBitmap);
CBitmap *maskOldBMP = maskDC.SelectObject(&maskBMP);
ImageDC.SetBkColor(clr);// 设置透明色
maskDC.BitBlt(0, 0, nWidth, nHeight, &ImageDC, nXsrc, nYsrc, SRCCOPY);
//设置背景色为黑色,前景色为白色,将掩码位图与原位图相"与"
ImageDC.SetBkColor(RGB(0, 0, 0));
ImageDC.SetTextColor(RGB(255, 255, 255));
ImageDC.BitBlt(0, 0, nWidth, nHeight, &maskDC, nXsrc, nYsrc, SRCAND);
//设置背景色为白色,前景色为黑色,将掩码位图与背景进行“与”运算
pDestDC->SetBkColor(RGB(255, 255, 255));
pDestDC->SetTextColor(RGB(0, 0, 0));
pDestDC->BitBlt(nXDest, nYDest, nWidth, nHeight, &maskDC, nXsrc, nYsrc, SRCAND);
// "或"运算,生成最终效果
pDestDC->BitBlt(nXDest, nYDest, nWidth, nHeight, &ImageDC, nXsrc, nYsrc, SRCPAINT);
if (pOldBMP) ImageDC.SelectObject(pOldBMP);
ImageDC.DeleteDC();
if (maskOldBMP) maskDC.SelectObject(maskOldBMP);
maskDC.DeleteDC();
if (maskBMP.m_hObject) maskBMP.DeleteObject();
}