GetTextExtentPoint32W function (wingdi.h)
The GetTextExtentPoint32 function computes the width and height of the specified string of text.
Syntax
BOOL GetTextExtentPoint32W(
[in] HDC hdc,
[in] LPCWSTR lpString,
[in] int c,
[out] LPSIZE psizl
);
Parameters
[in] hdc
A handle to the device context.
[in] lpString
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.
[in] c
The length of the string pointed to by lpString.
[out] psizl
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.
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.
Note
The wingdi.h header defines GetTextExtentPoint32 as an alias that 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 is 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 |