Solved

Apply color to a Dialog object

Posted on 2002-04-08
1
426 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 58
WinWaitActive parameters 12 31
Detect file exist or not 3 215
Increment column based of a FK 8 65
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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