您的位置:首页 > 其它

How to change the background color of an Edit Box

2006-10-17 22:06 751 查看
How to change the background color of an Edit Box
http://www.codeproject.com/cpp/cppfaq10dec04-23jan05.asp
You can change the background color of an edit control in a dialog by handling the
WM_CTLCOLOR
message in the dialog

class MyDialog : public CDialog {

//...

COLORREF _BkgColor;

HBRUSH _BkgBrush;

};

BOOL MyDialog::OnInitDialog()

{

//...

_BkgColor = RGB(0,255,0);

_BkgBrush = ::CreateSolidBrush(_BkgColor);

}

HBRUSH MyDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )

{

hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);

if (pWnd()->GetDlgCtrlId() == IDC_MY_EDIT_CONTROL) {

pDC->SetBkColor(_BkgColor);

hbr = _BkgBrush;

}

return hbr;

}

In the
OnInitDialog()
handler for the dialog, we initialize the background color value and create a brush in that color. The
WM_CTLCOLOR
handler is called
OnCtlColor
. The edit control for which we want to change the color has the resource ID
IDC_MY_EDIT_CONTROL
. We set the text background to our background color using
SetBkColor()
, and the overall background for the control by returning the brush we created.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: