Click to See Complete Forum and Search --> : Setting font for TextOut()?
MrDoomMaster
February 9th, 2005, 07:27 PM
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?
hankdane
February 9th, 2005, 09:09 PM
Some simplified code that should get you started:
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.
MrDoomMaster
February 10th, 2005, 01:41 PM
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!
MrViggy
February 10th, 2005, 03:00 PM
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
MrDoomMaster
February 10th, 2005, 07:53 PM
Thanks guys for the help!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.