GetTextMetrics function

The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font.

Syntax

BOOL GetTextMetrics(
  HDC          hdc,
  LPTEXTMETRIC lptm
);

Parameters

hdc

A handle to the device context.

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.

Requirements

   
Windows version Windows 2000 Professional [desktop apps only] Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll

See Also

Font and Text Functions

Fonts and Text Overview

GetTextAlign

GetTextExtentPoint32

GetTextFace

SetTextJustification

TEXTMETRIC