The CreateFont function creates a logical font that has specific characteristics. The logical font can subsequently be selected as the font for any device.
Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
|Operating Systems Supported|
|Requires Windows NT 3.1 or later; Requires Windows 95 or later|
Specifies the height, in logical units, of the font’s character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in nHeight in the following manner: Value
The font mapper transforms this value into device units and matches it against the cell height of the available fonts.
The font mapper uses a default height value when it searches for a match.
The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.
For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.
This mapping occurs when the font is used for the first time.
For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size:
nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
Specifies the average width, in logical units, of characters in the requested font. If this value is zero, the font mapper chooses a “closest match” value. The “closest match” value is determined by comparing the absolute values of the difference between the current device’s aspect ratio and the digitized aspect ratio of available fonts.
Specifies the angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to the base line of a row of text.
When the graphics mode is set to GM_ADVANCED, you can specify the escapement angle of the string independently of the orientation angle of the string’s characters.
When the graphics mode is set to GM_COMPATIBLE, nEscapement specifies both the escapement and orientation. You should set nEscapement and nOrientation to the same value.
The nEscapement parameter specifies both the escapement and orientation. You should set nEscapement and nOrientation to the same value.
Specifies the angle, in tenths of degrees, between each character’s base line and the x-axis of the device.
Specifies the weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default weight is used.
The following values are defined for convenience:
Specifies an italic font if set to TRUE.
Specifies an underlined font if set to TRUE.
Specifies a strikeout font if set to TRUE.
Specifies the character set. The following values are predefined:
Windows 95 only:
The OEM_CHARSET value specifies a character set that is operating-system dependent.
You can use the DEFAULT_CHARSET value to allow the name and size of a font to fully describe the logical font. If the specified font name does not exist, a font from any character set can be substituted for the specified font, so you should use DEFAULT_CHARSET sparingly to avoid unexpected results.
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 lpszFace parameter, make sure that the fdwCharSet value matches the character set of the typeface specified in lpszFace.
Specifies the output precision. The output precision defines how closely the output must match the requested font’s height, width, character orientation, escapement, pitch, and font type. It can be one of the following values:
Specifies the default font mapper behavior.
Instructs the font mapper to choose a Device font when the system contains multiple fonts with the same name.
Windows NT: This value instructs the font mapper to choose from TrueType and other outline-based fonts.
Windows 95: This value is not used.
Instructs the font mapper to choose a raster font when the system contains multiple fonts with the same name.
This value is not used by the font mapper, but it is returned when raster fonts are enumerated.
Windows NT: This value is not used by the font mapper, but it is returned when TrueType, other outline-based fonts, and vector fonts are enumerated.
Windows 95: This value is used to map vector fonts, and is returned when TrueType or vector fonts are enumerated.
Instructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font mapper returns to default behavior.
Instructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.
Applications can use the OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, and OUT_TT_PRECIS values to control how the font mapper chooses a font when the operating system contains more than one font with a specified name. For example, if an operating system contains a font named Symbol in raster and TrueType form, specifying OUT_TT_PRECIS forces the font mapper to choose the TrueType version. Specifying OUT_TT_ONLY_PRECIS forces the font mapper to choose a TrueType font, even if it must substitute a TrueType font of another name.
Specifies the clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. It can be one or more of the following values:
Specifies default clipping behavior.
Not used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated.
Windows NT: For compatibility, this value is always returned when enumerating fonts.
You must specify this flag to use an embedded read-only font.
When this value is used, the rotation for all fonts depends on whether the orientation of the coordinate system is left-handed or right-handed.
If not used, device fonts always rotate counterclockwise, but the rotation of other fonts is dependent on the orientation of the coordinate system.
For more information about the orientation of coordinate systems, see the description of the nOrientation parameter
Specifies the output quality. The output quality defines how carefully GDI must attempt to match the logical-font attributes to those of an actual physical font. It can be one of the following values:
Appearance of the font does not matter.
Appearance of the font is less important than when the PROOF_QUALITY value is used. For GDI raster fonts, scaling is enabled, which means that more font sizes are available, but the quality may be lower. Bold, italic, underline, and strikeout fonts are synthesized if necessary.
Character quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling is disabled and the font closest in size is chosen. Although the chosen font size may not be mapped exactly when PROOF_QUALITY is used, the quality of the font is high and there is no distortion of appearance. Bold, italic, underline, and strikeout fonts are synthesized if necessary.
Specifies the pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values:
The four high-order bits specify the font family and can be one of the following values:
Novelty fonts. Old English is an example.
Don’t care or don’t know.
Fonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New® are examples.
Fonts with variable stroke width and with serifs. MS® Serif is an example.
Fonts designed to look like handwriting. Script and Cursive are examples.
Fonts with variable stroke width and without serifs. MS Sans Serif is an example.
An application can specify a value for the fdwPitchAndFamily parameter by using the Boolean OR operator to join a pitch constant with a family constant.
Font families describe the look of a font in a general way. They are intended for specifying fonts when the exact typeface requested is not available.
Points to a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the null terminator. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts.
If lpszFace is NULL or points to an empty string, GDI uses the first font that matches the other specified attributes.
|If the function succeeds, the return value is a handle to a logical font. |
If the function fails, the return value is NULL. To get extended error information, call GetLastError.