windows_programming_notes.nbk: Home | Index | Next Page: GetTimeFormat | Previous Page: GetTextAlign


 GetTextExtentPoint32

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

    BOOL GetTextExtentPoint32(
      HDC hdc,           // handle to DC
      LPCTSTR lpString,  // text string
      int c,             // characters in string
      LPSIZE lpSize      // string size
    );

Parameters

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Windows NT/2000/XP: To get extended error information, call GetLastError.

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.

Windows 95/98/Me: For compatibility with Windows 3.1, GetTextExtentPoint32 adds an extra pixel for bold simulation fonts. However, the bold Tahoma font is not simulated, so it does not have any extra pixel. To correct for the extra pixel in a bold simulation font, decrease the length of every substring passed to GetTextExtentPoint32 by one pixel and add an extra pixel for the entire string.

Windows XP: 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.

Windows 2000: 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 returning the text extent, this function 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 using a font specifying a nonzero escapement, this function will not use the angle while computing the text extentthe application must convert it explicitly.

Windows 95/98/Me: Although GetTextExtentPoint32W exists on Windows 95/98/Me, it is supported by the Microsoft Layer for Unicode to give more consistent behavior across all Windows operating systems. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Requirements


windows_programming_notes.nbk: Home | Index | Next Page: GetTimeFormat | Previous Page: GetTextAlign


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time