Solved

Apply color to a Dialog object

Posted on 2002-04-08
1
416 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
ID: 6927159
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 107
Separate into files by filename 12 76
maxBlock challenge 30 112
zeroFront challenge 7 80
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

896 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

11 Experts available now in Live!

Get 1:1 Help Now