Hi.
Is it possible to change the background color and font color of a CEditView window? Please explain.
Thanks,
Kuphryn
Hi.
Is it possible to change the background color and font color of a CEditView window? Please explain.
Thanks,
Kuphryn
You can do it by subclassing your edit box.
It is basically providing the new window procedure for the
edit box, processing some messages inside it and calling the original window procedure for the messages you do not process. In MFC, it must be something alike, because MFC does not the things which can't be done by standard API techniques. It just conceals the core things and makes it harder to understand the backgrounds.
Okay. Thanks.
Kuphryn
Look at the 'OnCtlColor' function for your CEditView which should provide the capability you are after. You must return a brush handle (HBRUSH) from the function which is used to colour the background; you can also set other properties such as text colour with the CDC* provided to the function. You should use DeleteObject on any HBRUSH you create for this.
The win32 API analogue is a whole bunch of colour msgs, each specific to the control type: WM_CTLCOLORBTN (which doesn't do much),WM_CTLCOLOREDIT,WM_CTLCOLORLISTBOX,WM_CTLCOL ORSCROLLBAR,WM_CTLCOLORSTATIC. The process is the same: create an HBRUSH, return it in response to the msg and DeleteObject on it when done.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Thanks.
Kuphryn
Thanks.
I added a handler for =WM_CTLCOLOR. Is here the solution.
-----
HBRUSH CMyEditView::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
// m_BkColor is whatever background color you want to change to. You will make changes to m_BkColor by the time Windows
// repaints
pDC->SetBkColor(m_BkColor);
// m_FontColor is the text color
pDC->SetTextColor(m_FontColor);
// Return a handle to a CBrush. m_BkBrush is a local variable initialized to RGB(255, 255, 255)
return static_cast<HBRUSH>(m_BkBrush.GetSafeHandle());
}
-----
Special thanks to Joseph M. Newcomer of MSDN Newsgroup for pointing out "reflected" messages.
Kuphryn