InitDialog()
{
     CDC* pDC = GetDC();
     gdipDraw.Create(pDC->m_hDC,rect.Width(),rect.Height());
     button.SetBackDC(gdipDraw);//button类
}void GdixButton::SetBackDC( HDC hdc )
{
hBackDC = hdc;//为什么这个类对象变量可以隐式转化成HDC类型????
}GdipHDC hMemDC;
int width;
int height;Draw::GdipDraw()
:hMemDC(NULL)
,hBitmap(NULL)
,hOldBitmap(NULL)
,width(0)
,height(0)
{}bool GdipDraw::Create( HDC hDC,int w,int h )
{
Destroy(); if(hDC == 0 || w <= 0 || h <= 0) 
return false; hBitmap = ::CreateCompatibleBitmap(hDC,w,h);
if(hBitmap == 0) return false; hMemDC = ::CreateCompatibleDC(hDC);
if(hMemDC == 0)
{
::DeleteObject(hBitmap);
hBitmap = 0;
return false;
} hOldBitmap = (HBITMAP)::SelectObject(hMemDC,hBitmap);
width = w;
height = h; return true;
}

解决方案 »

  1.   

    两者之间有隐式类型转换
    http://blog.sina.com.cn/s/blog_523491650100gwii.html
      

  2.   

    void GdixButton::SetBackDC( HDC hdc )
    {
        hBackDC = hdc;//为什么这个类对象变量可以隐式转化成HDC类型????
    }这里面哪个是类对象变量?HDC hdc 这个不是。你说的转化 ,什么意思
      

  3.   


     button.SetBackDC(gdipDraw);
      

  4.   

     button.SetBackDC(gdipDraw);
    //纠结这些无聊的事,有意思吗
      

  5.   

    hBackDC是cdc 还是hdc?谁没事和你纠结无聊的肯定是在找问题!
      

  6.   

    无语,你仔细看我说的了,
    SetBackDC函数的参数是什么类型,传的值是什么类型???
      

  7.   

    gdipDraw , 把这个变量的声明,还有它所属类的源码看看,是否有类型转化的重载函数。要不你就把源码都放上来吧。最关键的的东西没贴上来,
      

  8.   

    大哥说对了operator bool()const {return hMemDC != NULL;};
    operator HDC ()const{return hMemDC;}  这个???
    HDC GetDC() const {return hMemDC;}
      

  9.   

    CDC* pDC = GetDC();//局部变量的m_hDC传给第一个参数
    当这个函数被调用完毕之后,pDC地址不就释放了吗? 
    gdipDraw.Create(pDC->m_hDC,rect.Width(),rect.Height()); bool GdipDraw::Create( HDC hDC,int w,int h )
    {
    Destroy(); if(hDC == 0 || w <= 0 || h <= 0) 
    return false; hBitmap = ::CreateCompatibleBitmap(hDC,w,h);
    if(hBitmap == 0) return false; hMemDC = ::CreateCompatibleDC(hDC);//使用被释放地址的HDC资源使用,会有问题吧???
                                    //局部变量,在函数返回之后,只是地址被释放了吧。地址上的值 还在吧?
    if(hMemDC == 0)
    {
    ::DeleteObject(hBitmap);
    hBitmap = 0;
    return false;
    } hOldBitmap = (HBITMAP)::SelectObject(hMemDC,hBitmap);
    width = w;
    height = h; return true;
    }
      

  10.   

    局部变量应该没错
    operator HDC ()const{return hMemDC;}  这俩咋使用呢???
    HDC GetDC() const {return hMemDC;}