From:   http://wmnmtm.blog.163.com/blog/static/38245714201041535119716/
 
 
为了让对话框程序更为漂亮,一般都是在窗口的WM_ERASEBKGND消息处理函数OnEraseBkgnd中添加如下代码.
BOOL CMFCtestDlg::OnEraseBkgnd(CDC* pDC)
{// TODO: Add your message handler code here and/or call defaultCRect rect;CPaintDC dc(this);GetClientRect(&rect);dc.FillSolidRect(rect,RGB(0,255,0));//对话框背景显示为绿色return TRUE;// return CDialog::OnEraseBkgnd(pDC);
}打开MFC ClassWizard,选择Class Info项.然后在Advanced options下的Message filter选择: Window ,点击OK,关闭MFC ClassWizard,后,重新打开就可以看到WM_ERASEBKGND消息了.
对话框载入背景图也可以在WM_ERASEBKGND消息处理函数中进行.如下代码
BOOL CMFCtestDlg::OnEraseBkgnd(CDC* pDC)
{// TODO: Add your message handler code here and/or call defaultCRect rect;CPaintDC dc(this);GetClientRect(&rect);CDC dcMem;dcMem.CreateCompatibleDC(&dc);CBitmap bmpBKG;bmpBKG.LoadBitmap(IDB_DLGBITMAP);//载入位图,IDB_DLGBITMAP是在ResourceView里边导入的位图IDBITMAP bmp;bmpBKG.GetBitmap(&bmp);CBitmap* pOldBMP = dcMem.SelectObject(&bmpBKG);dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);return TRUE;// return CDialog::OnEraseBkgnd(pDC);
} 
查看/建立类向导/ClassInfo/Advanced Options/:Message filter:dialog->window