- static void TransparentBlt2(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
- HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT crTransparent)
- {
- HDC hImageDC, hMaskDC;
- HBITMAP hOldImageBMP, hImageBMP, hOldMaskBMP, hMaskBMP;
- hImageBMP = CreateCompatibleBitmap(hdcDest, nWidthDest, nHeightDest);
- hMaskBMP = CreateBitmap(nWidthDest, nHeightDest, 1, 1, NULL);
- hImageDC = CreateCompatibleDC(hdcDest);
- hMaskDC = CreateCompatibleDC(hdcDest);
- hOldImageBMP = (HBITMAP) SelectObject(hImageDC, hImageBMP);
- hOldMaskBMP = (HBITMAP) SelectObject(hMaskDC, hMaskBMP);
- if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc)
- {
- BitBlt(hImageDC, 0, 0, nWidthDest, nHeightDest,
- hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
- }
- else
- {
- StretchBlt(hImageDC, 0, 0, nWidthDest, nHeightDest,
- hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
- }
- SetBkColor(hImageDC, crTransparent);
- BitBlt(hMaskDC, 0, 0, nWidthDest, nHeightDest, hImageDC, 0, 0, SRCCOPY);
- SetBkColor(hImageDC, RGB(0,0,0));
- SetTextColor(hImageDC, RGB(255,255,255));
- BitBlt(hImageDC, 0, 0, nWidthDest, nHeightDest, hMaskDC, 0, 0, SRCAND);SetBkColor(hdcDest, RGB(255,255,255));
- SetTextColor(hdcDest, RGB(0,0,0));
- BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
- hMaskDC, 0, 0, SRCAND); // <-- 这一句在VC6下画出黑色的圆,在eVC下画出黑色的正方形。
- BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
- hImageDC, 0, 0, SRCPAINT); // <-- 这一句在VC6下画出棋子,在eVC下画出随机噪音。
- SelectObject(hImageDC, hOldImageBMP);
- DeleteDC(hImageDC);
- SelectObject(hMaskDC, hOldMaskBMP);
- DeleteDC(hMaskDC);
- DeleteObject(hImageBMP);
- DeleteObject(hMaskBMP);
- }
单步跟踪发现所有DC相关函数的返回值全为非零(成功)。
在网上搜索许久,找到的和我的问题最接近的帖子是:
http://bbs.tongji.net/thread-296414-1-1.html
但仍然不能解决我的问题。特请有经验的大虾指点一二。
[img=http://www.vbgood.com/attachments/month_0908/0908231331059c0055f4039699.jpg[/img]