GetTextMetricsA function (wingdi.h)
The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font.
Syntax
BOOL GetTextMetricsA(
[in] HDC hdc,
[out] LPTEXTMETRICA lptm
);
Parameters
[in] hdc
A handle to the device context.
[out] lptm
A pointer to the TEXTMETRIC structure that receives the text metrics.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Remarks
To determine whether a font is a TrueType font, first select it into a DC, then call GetTextMetrics, and then check for TMPF_TRUETYPE in TEXTMETRIC.tmPitchAndFamily. Note that GetDC returns an uninitialized DC, which has "System" (a bitmap font) as the default font; thus the need to select a font into the DC.
Examples
For an example, see "Displaying Keyboard Input" in Using Keyboard Input or Drawing Text from Different Fonts on the Same Line.
Note
The wingdi.h header defines GetTextMetrics as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | wingdi.h (include Windows.h) |
Library | Gdi32.lib |
DLL | Gdi32.dll |