Export (0) Print
Expand All

GetTextMetrics function

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

Syntax


BOOL GetTextMetrics(
  _In_   HDC hdc,
  _Out_  LPTEXTMETRIC lptm
);

Parameters

hdc [in]

A handle to the device context.

lptm [out]

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

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Wingdi.h (include Windows.h)

Library

Gdi32.lib

DLL

Gdi32.dll

Unicode and ANSI names

GetTextMetricsW (Unicode) and GetTextMetricsA (ANSI)

See also

Fonts and Text Overview
Font and Text Functions
GetTextAlign
GetTextExtentPoint32
GetTextFace
SetTextJustification
TEXTMETRIC

 

 

Community Additions

ADD
Show:
© 2014 Microsoft