[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Apply color to a Dialog object

I want to change the text color of an IDC_STATIC or an IDC_EDIT object in a dialog box.

How is this done?

Thanx
Dave
0
Smave
Asked:
Smave
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

To do that, using class wizard map WM_CTLCOLOR message to ur dialog and then modify it as

HBRUSH CColourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
     
     if(nCtlColor == CTLCOLOR_EDIT)
     {
          //Set the edit text attributes
          pDC->SetTextColor(RGB(255, 0, 0));          
     }
     else if(nCtlColor == CTLCOLOR_STATIC)
     {
          //Set the static text attributes
          pDC->SetTextColor(RGB(0, 0, 255));          
     }
     
     return hbr;
}

That will give u the required. If U want ot change the text color of a perticular control only then u need to check the window handle as

HBRUSH CColourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
     
     if((nCtlColor == CTLCOLOR_EDIT) && (pWnd->GetSafeHwnd() == ((CEdit *)GetDlgItem(IDC_EDIT1))->GetSafeHwnd()))
     {
          //Set the edit text attributes
          pDC->SetTextColor(RGB(255, 0, 0));          
     }
     else if(nCtlColor == CTLCOLOR_STATIC)
     {
          //Set the static text attributes
          pDC->SetTextColor(RGB(0, 0, 255));          
     }
     
     return hbr;
}

Try it out.
VinExpert
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now