Home

CreateFont

CreateFont is a Windows API function in the Graphics Device Interface (GDI) that creates a logical font whose attributes are specified by the caller. The function returns an HFONT handle, which can be selected into a device context for subsequent text drawing operations. The attributes include height and width (nHeight, nWidth) that determine the font cell size, escapement and orientation (nEscapement, nOrientation) for rotated text, the font weight (fnWeight) for boldness, and flags for italic, underline, and strikeout (fdwItalic, fdwUnderline, fdwStrikeOut). Additional parameters specify the character set (fdwCharSet), output precision, clipping precision, and quality (fdwOutputPrecision, fdwClipPrecision, fdwQuality), as well as the pitch and family and the typeface name (fdwPitchAndFamily, lpszFace).

On success, the return value is a nonzero HFONT; on failure, NULL is returned and GetLastError can

Limitations and notes: The font created by CreateFont is a logical font subject to system font mapping,

Related functions include CreateFontIndirect, DeleteObject, and SelectObject; you may also examine LOGFONT for the attribute structure.

provide
details.
After
creating
the
font,
you
typically
select
it
into
a
device
context
with
SelectObject,
perform
drawing
operations,
and
then
deselect
and
delete
the
object
with
DeleteObject
when
it
is
no
longer
needed.
so
the
actual
rendered
glyphs
may
vary
with
system
settings
and
available
typefaces.
For
precise
control
over
attributes,
CreateFontIndirect
can
be
used
with
a
LOGFONT
structure,
or
developers
may
prefer
modern
text
rendering
APIs
such
as
DirectWrite
for
consistent
rendering
across
devices.
CreateFont
remains
part
of
legacy
GDI
workflows
and
continues
to
be
used
in
existing
codebases.