Link to home
Start Free TrialLog in
Avatar of mattiaso
mattiaso

asked on

BackgroundColor on a CRichEditCtrl

How do I change the backgroundcolor on a CRichEditCtrl??
I've tried to call SetBackgroundColor in OninitialUpdate and in OninitDialog.
Avatar of JohnWeidner
JohnWeidner

You might try handling WM_ERASEBKGRND and paint the entire area using something like FillRect()
Use CWnd::OnCtlColor() to return brush to paint background og your control. You can check detail information about this function in VC++ help.
Avatar of mattiaso

ASKER

If i want to change the backgroundcolor of an editcontrol I can
catch the message like this:

// m_Brush is the desired backgroundcolor
if(nCtlColor==CtlColor_Edit)
{
         return m_Brush;
}

But there is no message for a RichEditCtrl.
mattiaso,

CRichEditCtrl::SetBackgroundColor() should do exactly what you need. Have you tried instructing the rich edit control to redraw itself after the method invocation?
BTW, have you tried changing the back color in other points of your app?

Davide Marcato.
I've tried Invalidate(), but that will not help.
Can I redraw the control in other ways than with Invalidate and InvalidateRect???
Can you give me an example of that and of how you change the background of an Richedit???
I've succed with editboxes and listboxes in OnCtlColor.
Did you call UpdateWindow() after Invalidate()/InvalidateRect()?
It sends the WM_PAINT message to the window (the rich edit control in this case) immediately.

Davide Marcato.
Now I've tried that, but it will not work.

In OnInitDialog :

m_Rich.SetBackgroundColor(FALSE,RGB(255,255,192));
Invalidate();
UpdateWindow();
Last attempt:
m_Rich.SetBackgroundColor(FALSE, RGB(128,128,128));
m_Rich.Invalidate();
m_Rich.UpdateWindow();

Davide Marcato.
Now I've tried that to but it's not working.
This problem is documented somewhere in MSDN...

Your trying to do the same thing as what VB does, right?  You're trying to just change the background color of a single control?

If that's what you're doing,  search MSDN for changing the color of an Edit control and you should find the code snippet.  I remember because the author said that it was a pain in the ass to do it in C/C++.
I know how to change the backgroundcolor of an EditCtrl.
But it looks like changing the backgroundcolor of a RichEditCtrl is different.
I will check i MSDN.
Adjusted points to 70
ASKER CERTIFIED SOLUTION
Avatar of stefanr
stefanr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My graphiccard(Cirrus Logic) couldn't show the colour i used  (RGB(255,255,192)) with 256 colours).
But your answer was rigth....