static void TransparentBlt2(CDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
    CDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, UINT crTransparent) {  CDC hImageDC, hMaskDC;
 CBitmap *hOldImageBMP, *hImageBMP, *hOldMaskBMP, *hMaskBMP;    hImageBMP->CreateCompatibleBitmap(&hdcDest, nWidthDest, nHeightDest);
 hMaskBMP->CreateBitmap(nWidthDest, nHeightDest, 1, 1, NULL);
 hImageDC.CreateCompatibleDC(&hdcDest);
 hMaskDC.CreateCompatibleDC(&hdcDest);
 hOldImageBMP = hImageDC.SelectObject(hImageBMP);
 hOldMaskBMP = hMaskDC.SelectObject(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);
 BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
     hImageDC, 0, 0, SRCPAINT);  SelectObject(hImageDC, hOldImageBMP);
 DeleteDC(hImageDC);
 SelectObject(hMaskDC, hOldMaskBMP);
 DeleteDC(hMaskDC);
 DeleteObject(hImageBMP);
 DeleteObject(hMaskBMP);
}
static void DrawTransBmp(CDC hdc, CDC hdcTmp, int xx, int yy, CBitmap *bmp) {
  SelectObject(hdcTmp, bmp);
  TransparentBlt2(hdc, xx, yy, 56, 56, hdcTmp, 0, 0, 56, 56, RGB(0, 255, 0));
}
问题:error C2664: 'TransparentBlt2' : cannot convert parameter 1 from 'class CDC' to 'class CDC'
这个问题是什么错误,求指教!!

解决方案 »

  1.   

    看了下你的函数,TransparentBlt2里面的CDC类型不像是系统的CDC类,像是HDC
      

  2.   

    可能你声明TransparentBlt2的参数是引用类型&
      

  3.   

    我这个函数的原型是用的HDC,但是我都改过了,现在只是参数名称是HDC原来的,类型却已经改过来了..
      

  4.   

    那你把TransparentBlt2的参数CDC用指针吧
      

  5.   

    你吧参数的类型改成 CDC hdcDest ?这样肯定是不行的么,要是使用HDC 要么使用CDC*类型。
    不信你可以试试 CDC dc1; CDC dc2; dc1 = dc2;也会同样包错。原因是CDC类没有"="操作符。
    你不能讲一个CDC类的参数传给另外一个CDC类型变量。
    这个就好像是CWnd myWnd1; CWnd myWnd2; myWnd1 = myWnd2;一样,在MFC中很多的类是不支持等号操作符的。
    我想原因恐怕是这些类一旦生成就和操作系统、资源、窗口、文件等之间存在一种相互锁定状态,如果你再次创建一个和它一模一样的变量,操纵起来系统、资源、窗口、文件等就会产生冲突。
    类似CDC CWnd类型的变量,一般都是通过使用指针(CDC*)或者句柄(HDC)来实现传递,并进而操作相关对象。

    所以,把函数改回去,传参数的时候注意类型就可以了。