Changing the font size in tree and list controls


I need to programatically increase the font size of a tree/list control.  I've tried using the CFont and LOGFONT objects but I get weird results.

I also need to reset the font size to its original state.

Here's what I tried for increasing the size:
 CFont new_font;
CFont* old_font;

//get the tree control's current font object
old_font = m_wndTree.GetFont();

//increase the size
lf.lfHeight+= 4;
lf.lfWidth += 2;

//create a new font with this adjusted information

It kind of works, but just once, and the text gets cut off.  Then when I try again during the same execution, the text disappears.

Then to reset the size, I do something similar:
CFont new_font;

//mDefaultFont is of type LOGFONT and is set when the dialog is initialized using (essentially) tree->getFont()->getLogFont();

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
The CFont needs to be a member variable of the class.  What you are doing is creating the font, setting the font for the tree/list then destroying the font leaving the tree/list with an invalid font for drawing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amritpal SinghCommented:
have a look at the following link
Amritpal SinghCommented:
marisademeglioAuthor Commented:
Adding the font object as a class member worked.  I also had to keep a int variable in the class to represent the current point size; not sure why it wasn't being retrieved correctly from the tree on each iteration.  Anyway, it works now.  
AndyAinscowFreelance programmer / ConsultantCommented:
Please accept the answer to close the question.  It isn't done automatically.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.