Solved

Changing Text color in Dialog

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

623 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