以Edit控件为例进行说明,在Dialog类中,相应WM_CTLCOLOR消息。就是OnCtlColor(),那里面判断传入进来的ID号为你要的编辑控件,然后,用得到的DC,设置字体,颜色,最后返回一个笔刷,这个笔刷,就是要用来刷Edit空间背景的笔刷。
首先在自己需要设置界面的对话框上点击右键-->建立类向导-->加入WM_CTLCOLOR消息-->自动生成OnCtlColor()函数,此函数可以对本对话框的控件的界面外观做修饰。
集体步骤为:
在头文件里定义一个CBrush brush;
在该窗口初始化时:
brush.CreateSolidBrush(RGB(255,0,0));
再重载:
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd-> m_hWnd == m_static.m_hWnd )
{
pDC-> SetBkColor(RGB(255,0,0));
return (HBRUSH)brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}