你試試這個方法吧 在初始化函數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; }