Solved

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

Posted on 1998-09-09
2
158 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
  • 2
2 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 20 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now