Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ffmpeg - "rtsp://...... Operation not permitted" 4 73
java ^ examples 8 62
post4 challenge 28 91
building a service to accessed via telnet client, want colors ? 4 80
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…
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…

948 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

19 Experts available now in Live!

Get 1:1 Help Now