Best way to change text attributes during runtime? 
Author Message
 Best way to change text attributes during runtime?

Hi,

I'm learning MFC more or less by myself, coming from a VB background,
and having read through a book about the win32 API.
I want a simple control on my dialog box, to display text, but with
the option of being able to change the font, the font's size, and the
background/foreground color in run time, similar to the label control
in VB.
As far as I've seen, there isn't anything like the label control
available directly in VC, but there are probably hundreds of ways to
achieve the same effect.  I've managed to think up 3 ways, but I'm not
sure which one would be best.
So which method is best?  Or is there a better one?

1) Use the ActiveX control called "Microsoft Forms 2.0 Label" which is
(as I understand it) the real thing from VB (or at least from VBA, and
since I'm using VB 6 it's practically the same, I guess).  

But, if I want to avoid using ActiveX controls in my app, then...
2) Do it the hard(?) way: sub-class a CStatic control and add a few
functions to set/get font, background color, etc., and during its
OnPaint event set the font, colors, and then write the text.
(BTW, after initially having trouble with writing the text during
OnPaint, I've tried to be smart and use CtlColor to set the colors and
the font, relegating the actual output to OnPaint, but of course it
bombed on me... The font I selected was never released... so I got
into trouble)
3) Use the Rich Edit control (through the CRichEditCtrl class).  I'm
not sure if it's "ok" to use it for displaying purposes only (not
editing), I mean, I don't know whether there are any issues involved
that I should be aware of, other than disable the control, and hiding
the selection when I select the text to change its attributes in run
time.

Is there a more straightforward way to do this, without using the
ActiveX control?

Thanks,
Orwen.



Wed, 20 Mar 2002 03:00:00 GMT  
 Best way to change text attributes during runtime?

Quote:
> But, if I want to avoid using ActiveX controls in my app, then...
> 2) Do it the hard(?) way: sub-class a CStatic control and add a few
> functions to set/get font, background color, etc., and during its
> OnPaint event set the font, colors, and then write the text.

No you don't need to do that!! Eek! :)

1. Fonts
Declare a CFont member variable (must be a member variable so it exists for
the lifetime of your CStatic) and use CreateFontIndirect after populating a
LOGFONT struct which describes your font, then CWnd::SetFont.

2. Colours

WM_CTLCOLOR allows you to change the text & background colours for a Windows
control.

Quote:

> Is there a more straightforward way to do this, without using the
> ActiveX control?

--
Scott Tunstall
Senior Software Developer
MFC & COM developer
Altor Ego

Tel: (0141) 566 2000

Download C64 Boulderdash source code at:
www.kwikrite.clara.net/bdash/



Wed, 20 Mar 2002 03:00:00 GMT  
 Best way to change text attributes during runtime?

Quote:
>1. Fonts
>Declare a CFont member variable (must be a member variable so it exists for
>the lifetime of your CStatic) and use CreateFontIndirect after populating a
>LOGFONT struct which describes your font, then CWnd::SetFont.

Thanks, I've forgotten about SetFont.

Orwen.



Thu, 21 Mar 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. changing the text of Static Text at runtime?

2. Change mdi background during runtime

3. value of struct member changes during runtime

4. adodc - changing the filter during runtime is possible?

5. Changing a Dialog's CAPTION during runtime

6. How To change a LTEXT Resource during runtime?

7. How to change language of interface during runtime?

8. adodc: changing filter during runtime is possible?

9. Q Menu item change during runtime (2)

10. Q: How can I change menu items during runtime

11. Changing Tab Order during runtime

12. How To change a LTEXT Resource during runtime?

 

 
Powered by phpBB® Forum Software