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
Solved

Changing Text color in Dialog

Posted on 2004-08-26
8
204 Views
Last Modified: 2010-04-01
In formview class,i have a bmp loaded on screen having data displayed on it.On right clicking on that data,a dialog appears having information of that var in STATIC control.Now i want to change the color of some of information in dialog box.
e.g
In right click event,a Dlg shows values :

sprintf(buffer,"%f %f %s",m_HSCALE,m_YSCALE,m_string);
CWnd* pStaticWnd= pDlg->GetDlgItem(IDC_STATIC1);
 pStaticWnd->SetWindowText(buffer);
pDlg->Show....
now i want to change the textcolor of m_HSCALE value to green.How can i achieve this..as SetTextColor func changes the color of whole text in Static Control.?
cancermcs
0
Comment
Question by:cancermcs
  • 3
  • 2
8 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 20 total points
ID: 11910045
You can do this without any sort of owner-draw function.

Why don't you display your info in separated static controls?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11910050
Sorry, typo. I mean you CANNOT do this with any sort of owner draw function.
You can read about custom static controls at:
http://www.codeproject.com/staticctrl/
0
 
LVL 2

Expert Comment

by:carribus
ID: 11910593
Your question is interesting because you want PART of the text displayed in the static to be a different colour...
Let me start by showing you how to set a static controls text colour (the whole string will be drawn in this colour)...

What you want to do is handle the WM_CTLCOLOR message that your dialog receives on each paint...

You do this by with the OnCtlColor() handler...

here is a sample that will turn YOUR static text green :

------------- START -----------------

HBRUSH YourDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
  HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

  if ( nCtlColor == CTLCOLOR_STATIC )
  {
    if ( pWnd->GetDlgCtrlID() == IDC_STATIC1 )
    {
      pDC->SetTextColor( RGB(0,255,0) );
    }
  }

  return hbr;
}

---------- END --------------

However, if you want select parts of your static text to be a different colour, then you will need to either create your own static control, or download one of the many static controls available on the code sites. I know that http://www.codeproject.com has a few of these types of controls.

Take care,
Peter
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11910615
As I said, there is no way to display different color portions of a static control with standard CStatic methods, unique way is owner-draw as explained in some examples of the link I've posted.
0
 
LVL 2

Expert Comment

by:carribus
ID: 11910626
agreed :) was just offering an alternative route... :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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