Freigeben über


CFont::CreatePointFont

This function provides a simple way to create a font of a specified typeface and point size.

BOOL CreatePointFont(
   int nPointSize,
   LPCTSTR lpszFaceName,
   CDC* pDC = NULL 
);

Parameters

  • nPointSize
    Requested font height in tenths of a point. (For instance, pass 120 to request a 12-point font.)

  • lpszFaceName
    A CString or pointer to a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 30 characters. The Windows EnumFontFamilies function can be used to enumerate all currently available fonts. If lpszFaceName is NULL, the GDI uses a device-independent typeface.

  • pDC
    Pointer to the CDC object to be used to convert the height in nPointSize to logical units. If NULL, a screen device context is used for the conversion.

Return Value

Nonzero if successful, otherwise 0.

Remarks

It automatically converts the height in nPointSize to logical units using the CDC object pointed to by pDC.

When you finish with the CFont object created by the CreatePointFont function, first select the font out of the device context, then delete the CFont object.

Example

// The code fragment shows how to create a font object,
// select the font object into a DC (device context) for text
// drawing, and finally delete the font object.

CClientDC dc(this);

CFont font;
VERIFY(font.CreatePointFont(120, _T("Arial"), &dc));

// Do something with the font just created...
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, _T("Hello"), 5);
dc.SelectObject(def_font);

// Done with the font. Delete the font object.
font.DeleteObject();

Requirements

Header: afxwin.h

See Also

Concepts

CFont Class

CFont Members

Hierarchy Chart

CFont::CreatePointFontIndirect

CFont::CreateFont