首先感谢Rupesh Shukla大神指点
Default implementation of WM_ERASEBKGND message handler erases invalidated areas and fills it with color of the brush window was register with.
After that, native drawing is done in WM_PAINT handler. If you return TRUE from WM_ERASEBKGND you tell system to not to erase background and that is why you do not have background impact on your dialog.
After that, native drawing is done in WM_PAINT handler. If you return TRUE from WM_ERASEBKGND you tell system to not to erase background and that is why you do not have background impact on your dialog.
Thanks
相关提问点击打开链接
缺省地,WM_ERASEBKGND消息先擦除有效区域,然后然后用画刷填充有效区域,这时候通过WM_CTLCOLOR消息响应函数获取画刷,然后再处理WM_PAINT消息,如果你在WM_ERASEBKGND函数里面返回TRUE的话,就不会去调用默认的处理方法,也就不会发送WM_CTLCOLOR消息
一个没有确定和取消按钮的对话框,它发送消息是这样的
WM_ERASEBKGND-->WM_CTLCOLOR(此时是整个对话框需要确定window画刷,),然后在发送WM_PAINT消息,
如果在WM_ERASEBKGND响应消息返回TRUE,则不会去调用默认的消息处理方法,那么自然不会调用WM_CTLCOLOR消息的处理函数;顺序为
WM_ERASEBKGND--WM_PAINT,如此循环
至此在WM_ERASEBKGND处理函数里面贴出来的图已经显示出来了,但是背景色没有改变,既然不能用到默认的调用WM_CTLCOLOR消息的处理函数,那么我们就可以先画背景,然后在贴图,代码如下:
BOOL CControl5Dlg::OnEraseBkgnd(CDC* pDC)
{
this->OnCtlColor(pDC,this,CTLCOLOR_DLG);
BITMAP m_bitinfo;
m_bitmap.GetBitmap(&m_bitinfo);
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);
dcCompatible.SelectObject(&m_bitmap);
pDC->StretchBlt(0,0,m_bitinfo.bmWidth,m_bitinfo.bmHeight,&dcCompatible,0,0,m_bitinfo.bmWidth,m_bitinfo.bmHeight,SRCCOPY);
return true;
//return CDialog::OnEraseBkgnd(pDC);
}
HBRUSH CControl5Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_DLG:
return m_brush;
break;
}
return hbr;
}
如此效果如下: