0

I have CDialg and CEdit Control on dialog. So, to paint CEdit control without sub-classing CEdit Class, I used CDialog::OnCtlColor like this.

if( nCtlColor == CTLCOLOR_EDIT )
{
    pDC->SetBkColor(RGB(200, 255, 200));
}

But as you can see, that it omits some margin area of edit control.

How can I paint it whole window Rect of CEdit?

Image

Jawa
  • 2,312
  • 6
  • 33
  • 36
Jay Kim
  • 113
  • 11

1 Answers1

2

You also need to return a brush with the correct colour, so create a brush in the dialog constructor

#define EDITCOLOR RGB(200, 255, 200)
m_brEdit.CreateSolidBrush(EDITCOLOR);

and in the OnCtlColor() function,

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_EDIT)
{   pDC->SetBkColor(EDITCOLOR);
    hbr = m_brEdit;
}
return hbr;
Edward Clements
  • 4,917
  • 2
  • 19
  • 27
  • That works like a dream. Thanks Edward. I was trying to paint Edit control via FillSolidRect() on dialogs paint function. ::GetDc() to get DC of edit control and paint it. But this is much simple and elegant. Thanks. – Jay Kim Nov 01 '14 at 10:57
  • If you are happy with the answer, please accept and/or upvote the answer -- see http://stackoverflow.com/help/someone-answers – Edward Clements Nov 02 '14 at 08:13