CWindow.CreateFontmethod
Creates a DPI aware logical font.
Syntax
FUNCTION CreateFont (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 HFONT
Parameters
| Name | Description | |
|---|---|---|
wszFaceName | A 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. | |
lPointSize | Specifies the height, in logical units, of the font's character cell or character. | |
lWeight | Specifies the weight of the font in the range 0 through 1000. If this value is zero, a default weight is used. | |
bItalic | Specifies an italic font if set to CTRUE. | |
bUnderline | Specifies an underlined font if set to CTRUE. | |
bStrikeOut | Specifies a strikeout font if set to CTRUE. | |
bCharSet | Specifies 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. |
Return value
A handle to a logical font indicates success. NULL indicates failure. To get extended error information, call GetLastError.
Description
Creates a DPI aware logical font.
Example
hFont = CWindow.CreateFont("MS Sans Serif", 8, FW_NORMAL, , , , DEFAULT_CHARSET) hFont = CWindow.CreateFont("Courier New", 10, FW_BOLD, , , , DEFAULT_CHARSET) hFont = CWindow.CreateFont("Marlett", 8, FW_NORMAL, , , , SYMBOL_CHARSET)
Reference
- Include file
CWindow.inc - Defined in AfxNova/CWindow.inc:1478
- Documented in Windows/Windows GUI/CWindow Class.md
- Topic: CWindow Class