Solved

Apply color to a Dialog object

Posted on 2002-04-08
1
414 Views
Last Modified: 2013-11-20
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
Comment
Question by:Smave
1 Comment
 
LVL 8

Accepted Solution

by:
VinExpert earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now