Help Center

CWindow.SetFontmethod

Creates a DPI aware logical font and sets it as the default font.

WindowsmethodCWindow.incdocumented

Syntax

FUNCTION SetFont (BYREF wszFaceName AS WSTRING, BYVAL lPointSize AS LONG, BYVAL lWeight AS LONG = FW_NORMAL, BYVAL bItalic AS UBYTE = FALSE, BYVAL bUnderline AS UBYTE = FALSE, BYVAL bStrikeOut AS UBYTE = FALSE, BYVAL bCharSet AS UBYTE = DEFAULT_CHARSET) AS LONG

Parameters

NameDescription
wszFaceNameA string that specifies the typeface name of the font. The length of this string must not exceed 31 characters. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts. If wszFaceName is an empty string, GDI uses the first font that matches the other specified attributes.
lPointSizeSpecifies the height, in logical units, of the font's character cell or character.
lWeightSpecifies the weight of the font in the range 0 through 1000. If this value is zero, a default weight is used.
bItalicSpecifies an italic font if set to CTRUE.
bUnderlineSpecifies an underlined font if set to CTRUE.
bStrikeOutSpecifies a strikeout font if set to CTRUE.
bCharSetSpecifies the character set. The following values are predefined:
ANSI_CHARSET, BALTIC_CHARSET, CHINESEBIG5_CHARSET, DEFAULT_CHARSET, EASTEUROPE_CHARSET, GB2312_CHARSET, GREEK_CHARSET, HANGUL_CHARSET, MAC_CHARSET, OEM_CHARSET, RUSSIAN_CHARSET, SHIFTJIS_CHARSET, SYMBOL_CHARSET, TURKISH_CHARSET.
Korean Windows: JOHAB_CHARSET.
Middle-Eastern Windows: HEBREW_CHARSET, ARABIC_CHARSET.
Thai Windows: THAI_CHARSET.
The OEM_CHARSET value specifies a character set that is operating-system dependent. DEFAULT_CHARSET is set to a value based on the current system locale. For example, when the system locale is English (United States), it is set as ANSI_CHARSET. Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font. This parameter is important in the font mapping process. To ensure consistent results, specify a specific character set. If you specify a typeface name in the wszFaceName parameter, make sure that the bCharSet value matches the character set of the typeface specified in wszFaceName.
nWidthThe new width of the client area of the control.
nHeightThe new height of the client area of the control.

Return value

CTRUE or FALSE.

Description

Creates a DPI aware logical font and sets it as the default font.

Example

pWindow.SetFont("MS Sans Serif", 8, FW_NORMAL, , , , DEFAULT_CHARSET) pWindow.SetFont("Courier New", 10, FW_BOLD, , , , DEFAULT_CHARSET) pWindow.SetFont("Marlett", 8, FW_NORMAL, , , , SYMBOL_CHARSET)

Reference

  • Include file CWindow.inc
  • Defined in AfxNova/CWindow.inc:1525
  • Documented in Windows/Windows GUI/CWindow Class.md
  • Topic: CWindow Class