
How to change background color Of CEdit?
Hi!
Quote:
> Think you,your help.I write it as so:
> HBRUSH CMMsgEdit::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
> CBrush brush(RGB(0,0,0));
> if (nCtlColor== CTLCOLOR_EDIT )
> {
> // set the background color to Black.
> pDC->SetBkColor(RGB(0, 0, 0));
> // Set the text color to White
> pDC->SetTextColor(RGB(255,255,255));
> }
> return brush;
> }
Don't leave the CBrush a local variable. Either make it static or a member of the CMMsgEdit class.
The CBrush destructor will call DeleteObject when your function returns, so as it stands your
returned HBRUSH is invalid by the time the caller receives it. Also, do you mean to be returning a
black brush for everything?
HTH,
Jeff...
--
Please post all follow-ups to the newsgroup only.