CWnd::OnCtlColor
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );nCtlColorContains one of the following values, specifying the type of control: CTLCOLOR_BTN Button control//这个
CTLCOLOR_DLG Dialog box
CTLCOLOR_EDIT Edit control
CTLCOLOR_LISTBOX List-box control
CTLCOLOR_MSGBOX Message box
CTLCOLOR_SCROLLBAR Scroll-bar control
CTLCOLOR_STATIC Static control
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );nCtlColorContains one of the following values, specifying the type of control: CTLCOLOR_BTN Button control//这个
CTLCOLOR_DLG Dialog box
CTLCOLOR_EDIT Edit control
CTLCOLOR_LISTBOX List-box control
CTLCOLOR_MSGBOX Message box
CTLCOLOR_SCROLLBAR Scroll-bar control
CTLCOLOR_STATIC Static control
HBRUSH CParent::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_EDIT:
pDC->SetBkColor(m_crBkGrdColor);
pDC->SetTextColor(m_crTextColor);
break;
....
}
return hbr;
}
in .h
public:
HBRUSH m_hBrush;
in .cpp
在构造函数中创建对象:
m_hbrush=CreateSolidBrush(RGB(255,255,0));//用来设置Edit的背景色为黄色
...
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_EDIT)
{
pDC->SetBkMode (TRANSPARENT);
//set the color of the character
pDC->SetTextColor (RGB(255,0,0));//设置空间的字体颜色为红色
return m_hbrush;//控件的背景色
}
//other codes
....
}