Link to home
Start Free TrialLog in
Avatar of jade03
jade03

asked on

change edit box background color on condition

There are many examples on the board regarding how to change the background color of an edit control when an application starts up, mainly by implementing the WM_CTLCOLOR and putting in the OnCtlColor() method. That part I understand...

What I'm looking for is, not for the edit box color to change on startup, but ONLY when it's empty. So I have a check in the code, if the string in the edit box is empty, I want to call a function to change the color of the edit box so it can bring the user's attn to it.

any ideas? I can create a func to do it, but it seems like I would need to pass it the CDC param? But where do I get this param?
Avatar of jade03
jade03

ASKER

actually, I have half of it working so far...instead of just changing the color of the edit box, it changes the color of the entire dialog bg plus the edit box.

Another little thing: IDC_TABONE_HOST is a CIPAddressCtrl while IDC_TABONE_PRT_NUM is a CEdit, and the edit box one changes color, but the CIPAddressCtrl doesn't....any ideas?


This this what I have in my code:

.h
      CBrush m_brush;
      COLORREF m_bgColor, m_txtColor;
      BOOL m_changeColor;


.cpp

constructor:
                 m_bgColor = RGB(255,255,0); // yellow background
       m_txtColor = RGB(0,0,0); // black text
       m_brush.CreateSolidBrush(m_bgColor);

       m_changeColor = FALSE;


// do my checking condition, if true:
      m_changeColor = TRUE;
      GetDlgItem(IDC_TABONE_HOST)->RedrawWindow();
      GetDlgItem(IDC_TABONE_PRT_NUM)->RedrawWindow();

HBRUSH CTabOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
            // Call the base class implementation first! Otherwise, it may
            // undo what we're trying to accomplish here.
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

            // change background color of
            // host and port field in tab one
            // ONLY if no config file is present
      if(m_changeColor)
      {
            if (pWnd->GetDlgCtrlID() == IDC_TABONE_PRT_NUM ||
                  pWnd->GetDlgCtrlID() == IDC_TABONE_HOST )
            {
                  pDC->SetBkColor(m_bgColor);
                  pDC->SetTextColor(m_txtColor);
            }

            hbr = m_brush;
      }
   
      return hbr;
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jade03

ASKER

I got it to work now...checking on the nCtlColor, and only setting the bk and txt color if it's the correct control.

However, I'm still not sure if the IP address control is part of the nCtlColor list...I didn't see it listed in msdn's doc....so the part on coloring the IP address control is still not being done...

any ideas on that?
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jade03

ASKER

thanx, guys! sorry for the late acceptance of your answers.