如何改变对话框背景颜色

假设您的对话框类是CBgDlg

1. 在头文件中加入 Cbrush 的成员变量
class CBgDlg: public CDialog
{
...
CBrush m_brush;
...
}

2. 重载OnInitDialog函数
BOOL CBgDlg::OnInitDialog()
{
...
m_brush.CreateSolidBrush(RGB(255, 255, 255)); // 白色的背景
...
}

3. 增加对WM_CTLCOLOR 的处理方法。
HBRUSH CBgDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
...
//返回颜色(或者说改变了背景色)
return m_brush;// 默认情况下是返回 hbr;
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus