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,336
  • 6
  • 34
  • 39
Jay Kim
  • 123
  • 1
  • 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
  • 5,040
  • 2
  • 21
  • 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