Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing Text color in Dialog

Posted on 2004-08-26
8
Medium Priority
?
210 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 80 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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.
Suggested Courses

916 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