|
-
February 9th, 2005, 08:27 PM
#1
Setting font for TextOut()?
I've read MSDN on EnumFontFamilesEx(), and EnumFonts(), but it really makes no sense to me. They don't show you examples of how to change the font used by TextOut().
I want to set TextOut() to use a monospaced font, like "Courier New". Can someone paste a code example of how to do this? Avoid using callback functions if possible, I want this to be simple, small, clean code... if at all possible.
Thank you!
Also, what is the 'typeface name' of a font?
-
February 9th, 2005, 10:09 PM
#2
Re: Setting font for TextOut()?
Some simplified code that should get you started:
Code:
HFONT hfnt = CreateFontIndirect(&myFont);
HFONT hfntSav = NULL;
if (hfnt)
hfntSav = SelectObject(hdc, hfnt);
//Draw text...
if (hfntSav)
{
SelectObject(hdc, hfntSav);
DeleteObject(hfnt);
}
"Courier New" would be the typeface name. You can enumerate the fonts installed on a system if you are in doubt about whether the font you want to use is available, or need a list for UI purposes. "Courier New" comes with the system and should be fairly safe to assume. Use FF_DONTCARE as the family.
Henri Hein
Principal Engineer, Propel
Do not credit Propel with my views or opinions.
-
February 10th, 2005, 02:41 PM
#3
Re: Setting font for TextOut()?
Is there a simplier process, a function that accepts a face name and creates an HFONT object from it?
I was told there is such a function, but this person couldn't remember what the name of the function was.
THank you!
-
February 10th, 2005, 04:00 PM
#4
Re: Setting font for TextOut()?
Well, there is "CFont::CreatePointFont", however that is a member of the MFC class CFont.
I don't believe that there is a native WinAPI call that is equivelent to this. Sorry!
Viggy
-
February 10th, 2005, 08:53 PM
#5
Re: Setting font for TextOut()?
Thanks guys for the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|