Solved

Changing Text color in Dialog

Posted on 2004-08-26
8
201 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now