[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Apply color to a Dialog object

Posted on 2002-04-08
1
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
VinExpert earned 150 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

649 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