![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
添加对话框背景图片
//1.在对话框头文件件定义CBrush m_brBk;
//2.
HBRUSH CxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (pWnd == this)
{
return m_brBk;
}
}
//3.
BOOL CxxDlg::OnInitDialog()
{
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
m_brBk.CreatePatternBrush(&bmp);
bmp.DeleteObject();
}
点击切换背景图片:
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP2);
m_brBk.DeleteObject(); //先delete
m_brBk.CreatePatternBrush(&bmp);
bmp.DeleteObject();
Invalidate();
我的错就在 m_brBk创建新格式刷之前,没有把旧的删掉。m_brBk.DeleteObject();