GetTextExtentPoint32A function (wingdi.h)
The GetTextExtentPoint32 function computes the width and height of the specified string of text.
BOOL GetTextExtentPoint32A( [in] HDC hdc, [in] LPCSTR lpString, [in] int c, [out] LPSIZE psizl );
A handle to the device context.
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.
The length of the string pointed to by lpString.
A pointer to a SIZE structure that receives the dimensions of the string, in logical units.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
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.
For an example, see Drawing Text from Different Fonts on the Same Line.
The wingdi.h header defines GetTextExtentPoint32 as an alias which 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 not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|
|Header||wingdi.h (include Windows.h)|