CFont::CreatePointFont
This page is specific to:.NET Framework Version:1.12.03.54.0
MFC Library Reference
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

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View