Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

The way to change the size of the true type font without resource reducing.

Posted on 1998-09-09
2
Medium Priority
?
166 Views
Last Modified: 2013-12-03
Hi,
I created a true type font using CFont::CreateFont function in the
constructor of  my own class.
Whenever I change the MDI child window, the font size changes
according to the size of the MDI child window.
The Problem is that the GDI resource is reduced whenever the size
changes.
I think that this is caused because of the cache of the
true type font table.
I moved the font variable in my own class member to the local variable
in the function.
And the problem did not occurr again.
But I don't want to call CreateFont function whenever the function is
called.
Is there any other way to change the size of the true type font without
creating the font everytime?
Thanks for your time and effort.
0
Comment
Question by:sleepyrea
[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
  • 2
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 40 total points
ID: 1321922
Your resources were being reduced because you weren't freeing them when the CFont object was a member variable.  The resources are freed when the CFont object is destroyed.  When you repeatedly called CreateFont without destroying it, resources were lost.

Here's what you can do:

1.  Create a pointer to a CFont in your class as a member variable.  Initialize it to NULL in the constructor.

2.  In the OnSize window function do the following

2.1 If the CFont pointer is not NULL, delete it.
2.2 Use the new operator to create a new CFont object, pointed to by your member variable.
2.3 Use CreateFont to create a font of the size you need

3.  In your OnDraw routine do the following

3.1  Select the CFont pointed to by the member variable into the display context.
3.2  Do any drawing operations
3.3  Select the CFont out of the display context.

Note that OnSize is called before any draw operations so that there will be a CFont object there for the initial display.  Sorry there's no shortcut for eliminating the CreateFont calls, but at least this only makes the calls as often as necessary.
0
 
LVL 2

Expert Comment

by:jstolan
ID: 1321923
Oh yeah, you probably should make sure you delete the CFont in the destructor as well.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

722 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