Solved

CreateFont doesn't Create correct font

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

679 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