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?
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.
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!
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
Re: Setting font for TextOut()?
Thanks guys for the help!