c++mfccedit

How can I paint CEdit Control without uncovered area?


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


Solution

  • 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;