This topic has not yet been rated - Rate this topic

GetTextMetrics function

Applies to: desktop apps only

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

Minimum supported server

Windows 2000 Server

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

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ