Viltronics
asked on
CreateFont doesn't Create correct font
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,Fo nt_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.
AppView::OnDraw(CDC* pDC)
{
CString Font_Name,OutPut;
Font_Name = "Times New Roman"
CFont Font,*Old_Font;
Font.CreateFont(-12,0,0,0,
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.
ASKER
Edited text of question
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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)
ASKER
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();