Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateFont() never fails

132 views
Skip to first unread message

none

unread,
Sep 15, 2011, 8:12:10 PM9/15/11
to
Why is it that CFont::CreateFont(), CFont::CreateFontIndirect(), and
CFont::CreatePointFont() never fail, even if the font parameters are bad?

For example, this code always returns TRUE in my application:

CFont f;
f.CreateFont(-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "odsjfoerfj"));

Worse, the resulting font appears to be valid in every way. I can select
it into a DC and draw with it. It looks like Arial to me, actually.

Is there any way to know whether or not a CFont was "really" created,
instead of just sort of half created like this?

Thanks.

Nobody

unread,
Sep 15, 2011, 9:23:51 PM9/15/11
to
That's normal. If it can't find the requested font, it would try to find a
closer match based on the other attributes. This is not clearly documented
in CFont::CreateFont, but in the Win32 API function CreateFont().

CreateFont function (Windows):
http://msdn.microsoft.com/en-us/library/dd183499%28VS.85%29.aspx

Quote: "Because available fonts can vary from system to system, do not
assume that the selected font is always the same as the requested font. For
example, if you request a font named Palatino, but no such font is available
on the system, the font mapper will substitute a font that has similar
attributes but a different name. Always report the name of the selected font
to the user."

If you want to know if a particular font exists, you need enumerate the
fonts:

EnumFonts function (Windows)
http://msdn.microsoft.com/en-us/library/dd162622%28v=VS.85%29.aspx



Scott Gregg

unread,
Sep 16, 2011, 8:31:08 PM9/16/11
to
none <no...@none.none> wrote in
news:Xns9F61B922F95...@69.16.186.52:
How about CFont::AssertValid()?
0 new messages