(bmp格式)用CDialog的OnCtlColor()消息响应处理背景画刷。
加载位图资源IDB_BITMAP1,在Dlg类头文件中加入:
- CBrush m_brush;
在OnInitDialog()中加入:
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP1); //IDB_BITMAP1是图片资源ID
- m_brush.CreatePatternBrush(&bmp);
给Dlg类添加WM_CTLCOLOR消息处理函数OnCtlColor,修改return 为我们的画刷:
- HBRUSH CBackgroundDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- return (HBRUSH)m_brush;
- }