Solved

CreateFont doesn't Create correct font

Posted on 1997-07-16
4
696 Views
Last Modified: 2013-12-02
I have an app that allows users to select fonts from the available system fonts (Windows NT 4.0).  Some of the fonts seem to get mapped to a "default" font.  Here is a sample of the code in the OnDraw section of AppView...

AppView::OnDraw(CDC* pDC)
{

CString Font_Name,OutPut;
Font_Name = "Times New Roman"
CFont Font,*Old_Font;
Font.CreateFont(-12,0,0,0,0,0,0,0,0,0,0,0,0,Font_Name);
Old_Font = pDC->SelectObject(&Font);
OutPut = "Font name = " + Font_Name;
pDC->TextOut(50,50,OutPut);
pDC->SelectObject(Old_Font);
Font.DeleteObject();
}

This works fine, the output says...
Font name = Times New Roman
in the Times New Roman font (as would be expected), but if I set Font_Name = "WingDings", the output says...
Font name = WingDings
What should be displayed is a bunch of unreadable characters in the WingDings font.  The same thing happens with the "Script" font, and a few others.  CreateFont seems to map some fonts to their correct font, while setting others to some default font.  It makes no difference if the font is TT or not.

My question...
Why doesn't CreateFont work for some fonts, but it does for others?  Am I using CreateFont incorrectly?  I have tried setting some of the 0'ed out parameters, but I don't seem to be getting anywhere.

0
Comment
Question by:Viltronics
  • 3
4 Comments
 

Author Comment

by:Viltronics
ID: 1165192
Oops I forgot a few lines...
there should be

CFont Font,*Old_Font;

After the CreateFont line...

Old_Font = pDC->SelectObject(&Font);

and at the end of the routine...

pDC->SelectObject(Old_Font);
Font.DeleteObject();
0
 

Author Comment

by:Viltronics
ID: 1165193
Edited text of question
0
 
LVL 1

Accepted Solution

by:
belov earned 100 total points
ID: 1165194
When the font is created, system does not always
create a font that matches parameters you
supplied exactly. Fontmapper performs
selection of font that fit most the supplied
parameters from the fontmapper point of view.
One of important parameters is charset.
You must specify  DEFAULT_CHARSET in
charset parameter instead of 0 value and you will
see wingdings characters well :)
Default charset will try to use charset default
to _font_.


0
 

Author Comment

by:Viltronics
ID: 1165195
Thanks, I knew it had to be something easy.  Default_Charset is the one setting I didn't try because the help file for CreateFont had a big warning to try not to use this setting.  I just checked it out and it works (not that I really want WingDings, but I do want the other fonts)
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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 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

9 Experts available now in Live!

Get 1:1 Help Now