Solved

CreateFont doesn't Create correct font

Posted on 1997-07-16
4
699 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

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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…

932 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

10 Experts available now in Live!

Get 1:1 Help Now