Solved

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

Posted on 1998-09-09
2
160 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 117
mapAB Challlenge 35 146
wordappend challenge 8 181
Authenticate using sesu from script 7 36
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

832 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