Solved

Changing colors of a CStatic

Posted on 1998-11-24
2
271 Views
Last Modified: 2013-11-20
Changing the font of a CStatic is pretty easy ..

fontBox=new CFont;
fontBox->CreateFont(16,0,0,0,600,0,0,0,
      ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
      DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"arial");
m_title.SetFont(fontBox);

But to change the color of the text it isn't so easy ...
I've been reading tons of help files and I couldn't find
anything useful. Any help is wellcome.      
0
Comment
Question by:econde
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 100 total points
ID: 1325230
In the dialog override OnCtlColor (WM_CTLCOLOR), check for the id of your static control and set the color as you wish.

You can check the help for that message, it's pretty clear.
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1325231
To add to my answer, here's some code:

HBRUSH CDRegimes::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if( nCtlColor == CTLCOLOR_STATIC ) {
  if( pWnd->m_hWnd == GetDlgItem(IDC_YOUR_STATIC) ) {
    pDC->SetTextColor(RGB(100,100,100));
  }
}

return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}

It's something close to that.
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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

18 Experts available now in Live!

Get 1:1 Help Now