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;
}
http://blog.sina.com.cn/s/blog_523491650100gwii.html
{
hBackDC = hdc;//为什么这个类对象变量可以隐式转化成HDC类型????
}这里面哪个是类对象变量?HDC hdc 这个不是。你说的转化 ,什么意思
button.SetBackDC(gdipDraw);
//纠结这些无聊的事,有意思吗
SetBackDC函数的参数是什么类型,传的值是什么类型???
operator HDC ()const{return hMemDC;} 这个???
HDC GetDC() const {return hMemDC;}
当这个函数被调用完毕之后,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;
}
operator HDC ()const{return hMemDC;} 这俩咋使用呢???
HDC GetDC() const {return hMemDC;}