Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using fonts etc

Posted on 2003-11-02
7
Medium Priority
?
393 Views
Last Modified: 2013-12-03
I have some text being displayed on my form. How do I chnge the fonts for specifics words such as color, Bold, underline, font type etc.

example

m_string = "This is a TEST";

I would like the TEST to be underlined and set to a larger font etc, maybe new color.

Regards,
0
Comment
Question by:Maritimer
[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
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9666422
Try this link
http://www.codeproject.com/staticctrl/xhtmlstatic.asp - XHTMLStatic - An extra-lean custom control to display HTML

Good luck
0
 
LVL 1

Expert Comment

by:ragin_cajun
ID: 9676377
Is the text on your form static text controls or are you outputting it with the GDI functions like TextOut / DrawText ? There's a different method for altering the font with those 2 - please post I'll give you some examples.
0
 

Author Comment

by:Maritimer
ID: 9677932
I am using the static text control. I have looked through my books and have not bee able to find anything.
Due to the nature of this application I cannot import any custom controls outside of the functions Microsoft provides.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Expert Comment

by:ragin_cajun
ID: 9679035
Ok static text control - I had the same problem you did. Changing the color of the font involves one function, the font, another. You don't have to import any custom controls just do it like this:

For color:

You'll have to add the OnCtlColor message handler to your dialog. You can do this by selecting your dialog in the resource editor and from the message list add OnCtlColor. It'll automatically generate the frame for the function like so:

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

               // Here is what you'll add to change the color
               if (pWnd->GetDlgCtrlID() == IDC_MY_STATICTEXT_ID)
               {
                                // Now you've intercepted the correct static text control
                                // now make a colorref and set it to that color
                                COLORREF blue = RGB (0, 0, 255); // pure blue
                                pDC->SetTextColor(blue);
                                // this sets the background color of your text appropriately - I think you
                                // can use TRANSPARENT as well.
                                COLORREF bg =  GetSysColor( COLOR_3DFACE );
                                pDC->SetBkColor( bg );
                  
                                hbr = m_brush;
                }

                return hbr;
}

Declare your brush in your dialog class as:
CBrush m_brush;

And on InitDialog or wherever you like initialize its color like this:
//sets the color of this brush to the sys bg color
m_brush.CreateSolidBrush(GetSysColor(COLOR_3DFACE));



For font:

Pretty easy, you can use the SetFont function.

First create a font, look up LOGFONT on msdn.com.
The parameters for the font will include all that you are wondering about such as size, underline, strikethrough, type face, etc.

Once you have your font defined, you can simply create a control variable for the static text contol, then use:

my_statictext_control.SetFont(FontName, Redraw(t/f));

Then it will be drawn in the font you defined.

Goodluck, feel free to post any questions.
0
 

Author Comment

by:Maritimer
ID: 9679502
Thanks excellent answer.

I dont have time to try it today they have me do a quick litttle assignement.

However I understand the code. Is there anything else I should be aware of.

0
 
LVL 1

Accepted Solution

by:
ragin_cajun earned 200 total points
ID: 9681694
No that should be all you need to do, if you have questions post them.
0
 

Author Comment

by:Maritimer
ID: 9683810
Thanks again
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

610 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