From: jklioe on
I have a CEditView with ReadOnly set and I want to change the
background to white color and I do the following

ON_WM_CTLCOLOR_REFLECT()


HBRUSH CEditViewEx::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here


// TODO: Return a non-NULL brush if the parent's handler
should not
be called
COLORREF color;
CBrush brush;
brush.CreateSolidBrush(RGB(255, 255,255));
pDC->SetBkColor(RGB( 255, 255, 255 ));

return static_cast<HBRUSH>(brush.GetSafeHandle());

}

The problem that I face here is only the text backgroud turn white
while the rest of the view still remains greyed out
From: Volker Enderlein on
jklioe wrote:
> I have a CEditView with ReadOnly set and I want to change the
> background to white color and I do the following
>
> ON_WM_CTLCOLOR_REFLECT()
>
>
> HBRUSH CEditViewEx::CtlColor(CDC* pDC, UINT nCtlColor)
> {
> // TODO: Change any attributes of the DC here
>
>
> // TODO: Return a non-NULL brush if the parent's handler
> should not
> be called
> COLORREF color;
> CBrush brush;
> brush.CreateSolidBrush(RGB(255, 255,255));
> pDC->SetBkColor(RGB( 255, 255, 255 ));
>
> return static_cast<HBRUSH>(brush.GetSafeHandle());
>
> }
>
> The problem that I face here is only the text backgroud turn white
> while the rest of the view still remains greyed out

You are returning the local variable brush which is destroyed after the
function returns. So this is absolutely wrong.
Better try to make brush a member variable of CEditViewEx and return it.

Cheers Volker
From: njoycoding on
Hey

Thanks that solved my problem :)


On Jul 31, 12:27 pm, Volker Enderlein <vol...(a)ifm.tu-chemnitz.de>
wrote:
> jklioe wrote:
> > I have a CEditView with ReadOnly set and I want to change the
> > background to white color and I do the following
>
> > ON_WM_CTLCOLOR_REFLECT()
>
> > HBRUSH CEditViewEx::CtlColor(CDC* pDC, UINT nCtlColor)
> > {
> >         // TODO: Change any attributes of the DC here
>
> >         // TODO: Return a non-NULL brush if the parent's handler
> > should not
> > be called
> >         COLORREF color;
> >         CBrush brush;
> >         brush.CreateSolidBrush(RGB(255, 255,255));
> >         pDC->SetBkColor(RGB( 255, 255, 255 ));
>
> >         return static_cast<HBRUSH>(brush.GetSafeHandle());
>
> > }
>
> > The problem that I face here is only the text backgroud turn white
> > while the rest of the view still remains greyed out
>
> You are returning the local variable brush which is destroyed after the
> function returns. So this is absolutely wrong.
> Better try to make brush a member variable of CEditViewEx and return it.
>
> Cheers Volker- Hide quoted text -
>
> - Show quoted text -

From: Ajay Kalra on
On Jul 31, 6:26 am, "njoycod...(a)gmail.com" <njoycod...(a)gmail.com>
wrote:
> Hey
>
> Thanks that solved my problem :)
>
> On Jul 31, 12:27 pm, Volker Enderlein <vol...(a)ifm.tu-chemnitz.de>
> wrote:
>
> > jklioe wrote:
> > > I have a CEditView with ReadOnly set and I want to change the
> > > background to white color and I do the following
>
> > > ON_WM_CTLCOLOR_REFLECT()
>
> > > HBRUSH CEditViewEx::CtlColor(CDC* pDC, UINT nCtlColor)
> > > {
> > >         // TODO: Change any attributes of the DC here
>
> > >         // TODO: Return a non-NULL brush if the parent's handler
> > > should not
> > > be called
> > >         COLORREF color;
> > >         CBrush brush;
> > >         brush.CreateSolidBrush(RGB(255, 255,255));
> > >         pDC->SetBkColor(RGB( 255, 255, 255 ));
>
> > >         return static_cast<HBRUSH>(brush.GetSafeHandle());
>
> > > }
>
> > > The problem that I face here is only the text backgroud turn white
> > > while the rest of the view still remains greyed out
>
> > You are returning the local variable brush which is destroyed after the
> > function returns. So this is absolutely wrong.
> > Better try to make brush a member variable of CEditViewEx and return it..
>
> > Cheers Volker- Hide quoted text -
>
> > - Show quoted text -

Also, you dont need to create brush on each call to OnCtlColor. Create
it outside (constructor) and simply return the brush in this method.

--
Ajay