This topic has not yet been rated - Rate this topic

GetTextExtentPoint function

Applies to: desktop apps only

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

Note  This function is provided only for compatibility with 16-bit versions of Windows. Applications should call the GetTextExtentPoint32 function, which provides more accurate results.

Syntax

BOOL GetTextExtentPoint(
  __in   HDC hdc,
  __in   LPCTSTR lpString,
  __in   int cbString,
  __out  LPSIZE lpSize
);

Parameters

hdc [in]

A handle to the device context.

lpString [in]

A pointer to the string that specifies the text. The string does not need to be zero-terminated, since cbString specifies the length of the string.

cbString [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 GetTextExtentPoint 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. Also, 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 extent. The application must convert it explicitly.

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.

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

GetTextExtentPointW (Unicode) and GetTextExtentPointA (ANSI)

See also

Fonts and Text Overview
Font and Text Functions
GetTextExtentPoint32
SetTextCharacterExtra
SIZE

 

 

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