你试试这个方法吧 在初始化函数OnInitDialog()中加入: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP2); m_brBk.CreatePatternBrush(&bmp); bmp.DeleteObject(); return TRUE; // return TRUE unless you set the focus to a control } 在打开类向导,找到WM_CTLCOLOR消息,重载得对应函数OnCtlColor(),添加如下: HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd == this) { return m_brBk; } return hbr; }
********************************************************************************************************************************
不要用控件加背景图!可以直接加的!像下面这样做,我就是这样做的,没问题! 先载入一张图片,如ID为IDB_BITMAP 头文件中: CBrush m_brBk;//在public中定义 源文件中: 在初始化函数OnInitDialog()中加入: (或者在构造函数中) BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); CBitmap bmp; bmp.LoadBitmap(IDB_BITMAP); m_brBk.CreatePatternBrush(&bmp); bmp.DeleteObject(); return TRUE; // return TRUE unless you set the focus to a control } 再打开类向导,找到WM_CTLCOLOR消息,重载得对应函数OnCtlColor(), 添加如下: HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd == this) { return m_brBk; } return hbr; }