How to make the background color of the form lighter?

D.D.K-2637 966 Reputation points
2021-06-21T12:50:38.67+00:00

Hi,
On MFC form. I use 2 events OnCtlColor and OnEraseBkgnd
my purpose is:
with OnEraseBkgnd: i will assign background color as RGB(245, 245, 245)
with OnCtlColor : to set label (red text and background color to match the form) as well as textbox(CEdit) (red text and white background)
The code I use is as follows:

HBRUSH MFCFORM::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    UINT id = pWnd->GetDlgCtrlID();
    COLORREF normal = RGB(255, 255, 255);
    HBRUSH hbr = (HBRUSH)m_pbrush->GetSafeHandle();  //CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    //hbr=m_pEditBkBrush
    switch (nCtlColor)
    {
    case CTLCOLOR_STATIC:
   if (id == IDC_lbselectframe || id == IDC_lballframes) {   <--Label have text red-background same with form
 pDC->SetTextColor(red);
 pDC->SetBkColor(RGB(245, 245, 245));
 pDC->SetDCBrushColor(RGB(245, 245, 245));
 return (HBRUSH)GetStockObject(DC_BRUSH);
   }
   break;
    case CTLCOLOR_EDIT:
   if ((id == IDC_tboxcopy || id == IDC_tboxsavepath))  <--textbox have text red
   {
 pDC->SetTextColor(red);
 pDC->SetBkColor(normal);
 pDC->SetDCBrushColor(normal);
 return (HBRUSH)GetStockObject(DC_BRUSH);

   }
   break;
    default:
   ;
    }
    //pDC->SetBkColor(normal);
    return (HBRUSH)hbr;
}
BOOL MFCFORM::OnEraseBkgnd(CDC* pDC)
{
    CRect r;
    pDC->GetClipBox(&r);
    pDC->FillSolidRect(r, RGB(245, 245, 245)); 
    return TRUE;
}

after run code, label and textbox work as i expected , but the background form doesn't seem to get any brighter.
How can I make background lighter?

Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. D.D.K-2637 966 Reputation points
    2021-06-22T01:32:21.673+00:00

    Hi,
    my problem solved by using image instead.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.