Changing the font size in tree and list controls

Posted on 2004-11-19
Last Modified: 2013-12-03

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();

Question by:marisademeglio
    LVL 43

    Accepted Solution

    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.
    LVL 6

    Expert Comment

    by:Amritpal Singh
    have a look at the following link
    LVL 6

    Expert Comment

    by:Amritpal Singh

    Author Comment

    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.  
    LVL 43

    Expert Comment

    Please accept the answer to close the question.  It isn't done automatically.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    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…

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now