Solved

Changing Text color in Dialog

Posted on 2004-08-26
8
206 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
[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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

730 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