对话框背景可以用如下方法绘制:
1。处理WM_ERASEBKGND消息处理函数,在其中添加如下代码:
BOOL CCeDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBitmap m_bitmap;
BITMAP m_bmInfo;
m_bitmap.LoadBitmap(IDB_BITMAP1);
m_bitmap.GetObject(sizeof(m_bmInfo),&m_bmInfo);
CDC dc;
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&m_bitmap);
GetClientRect(m_rect);
pDC->StretchBlt(0,0,m_rect.Width(),m_rect.Height(),&dc,0,0,m_bmInfo.bmWidth,m_bmInfo.bmHeight,SRCCOPY);
dc.DeleteDC();
static int a=0;
a++;
CString str;
str.Format("%d",a);
TRACE("OnEraseBkgnd(CDC* pDC) "+str+"\r\n");
return true;//返回真
return CDialog::OnEraseBkgnd(pDC); //不执行自动生成的这个函数
}
2。
处理对话框的WM_SIZE消息,添加代码如下:
void CCeDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
Invalidate();
}
评论