Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreateFont doesn't Create correct font

Posted on 1997-07-16
4
Medium Priority
?
729 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 400 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

715 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