Solved

CreateFont doesn't Create correct font

Posted on 1997-07-16
4
726 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
[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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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.
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…

630 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