Export (0) Print
Expand All
6 out of 12 rated this helpful - Rate this topic

GetTextExtentPoint32 function

The GetTextExtentPoint32 function computes the width and height of the specified string of text.

Syntax


BOOL GetTextExtentPoint32(
  _In_   HDC hdc,
  _In_   LPCTSTR lpString,
  _In_   int c,
  _Out_  LPSIZE lpSize
);

Parameters

hdc [in]

A handle to the device context.

lpString [in]

A pointer to a buffer that specifies the text string. The string does not need to be null-terminated, because the c parameter specifies the length of the string.

c [in]

The length of the string pointed to by lpString.

lpSize [out]

A pointer to a SIZE structure that receives the dimensions of the string, in logical units.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Remarks

The GetTextExtentPoint32 function uses the currently selected font to compute the dimensions of the string. The width and height, in logical units, are computed without considering any clipping.

Because some devices kern characters, the sum of the extents of the characters in a string may not be equal to the extent of the string.

The calculated string width takes into account the intercharacter spacing set by the SetTextCharacterExtra function and the justification set by SetTextJustification. This is true for both displaying on a screen and for printing. However, if lpDx is set in ExtTextOut, GetTextExtentPoint32 does not take into account either intercharacter spacing or justification. In addition, for EMF, the print result always takes both intercharacter spacing and justification into account.

When dealing with text displayed on a screen, the calculated string width takes into account the intercharacter spacing set by the SetTextCharacterExtra function and the justification set by SetTextJustification. However, if lpDx is set in ExtTextOut, GetTextExtentPoint32 does not take into account either intercharacter spacing or justification. However, when printing with EMF:

  • The print result ignores intercharacter spacing, although GetTextExtentPoint32 takes it into account.
  • The print result takes justification into account, although GetTextExtentPoint32 ignores it.

When this function returns the text extent, it assumes that the text is horizontal, that is, that the escapement is always 0. This is true for both the horizontal and vertical measurements of the text. Even if you use a font that specifies a nonzero escapement, this function doesn't use the angle while it computes the text extent. The app must convert it explicitly. However, when the graphics mode is set to GM_ADVANCED and the character orientation is 90 degrees from the print orientation, the values that this function return do not follow this rule. When the character orientation and the print orientation match for a given string, this function returns the dimensions of the string in the SIZE structure as { cx : 116, cy : 18 }. When the character orientation and the print orientation are 90 degrees apart for the same string, this function returns the dimensions of the string in the SIZE structure as { cx : 18, cy : 116 }.

GetTextExtentPoint32 doesn't consider "\n" (new line) or "\r\n" (carriage return and new line) characters when it computes the height of a text string.

Examples

For an example, see 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

GetTextExtentPoint32W (Unicode) and GetTextExtentPoint32A (ANSI)

See also

Fonts and Text Overview
Font and Text Functions
ExtTextOut
SetTextCharacterExtra
SetTextJustification
SIZE

 

 

Build date: 6/12/2013

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.