GetTabbedTextExtent

3.0

  DWORD GetTabbedTextExtent(hdc, lpszString, cChars, cTabs, lpnTabs)    
  HDC hdc; /* handle of device context */
  LPCSTR lpszString; /* address of string */
  int cChars; /* number of characters in string */
  int cTabs; /* number of tab positions, */  
  int FAR* lpnTabs; /* address of array of tab positions */

The GetTabbedTextExtent function computes the width and height of a character string. If the string contains one or more tab characters, the width of the string is based upon the specified tab stops. GetTabbedTextExtent uses the currently selected font to compute the dimensions of the string.

Parameters

hdc

Identifies the device context.

lpszString

Points to a character string.

cChars

Specifies the number of characters in the text string.

cTabs

Specifies the number of tab-stop positions in the array pointed to by the lpnTabs parameter.

lpnTabs

Points to an array containing the tab-stop positions, in device units. The tab stops must be sorted in increasing order; the smallest x-value should be the first item in the array.

Return Value

The low-order word of the return value contains the string width, in logical units, if the function is successful; the high-order word contains the string height.

Comments

The current clipping region does not affect the width and height returned by the GetTabbedTextExtent function.

Since some devices do not place characters in regular cell arrays (that is, they kern the characters), the sum of the extents of the characters in a string may not be equal to the extent of the string.

If the cTabs parameter is zero and the lpnTabs parameter is NULL, tabs are expanded to eight times the average character width. If cTabs is 1, the tab stops are separated by the distance specified by the first value in the array to which lpnTabs points.

Example

The following example uses the LOWORD and HIWORD macros to retrieve the width and height of the string from the value returned by the GetTabbedTextExtent function:

LPSTR lpszTabbedText = "Column 1\tColumn 2\tTest of TabbedTextOut";
int aTabs[2] = { 150, 300 };
DWORD dwTabExtent;
WORD wStringWidth, wStringHeight;

dwTabExtent = GetTabbedTextExtent(hdc, /* handle of device context */
    lpszTabbedText,                    /* address of text          */
    lstrlen(lpszTabbedText),           /* number of characters     */
    sizeof(aTabs) / sizeof(int),       /* number of tabs in array  */
    aTabs);                            /* array for tab positions  */

wStringWidth = LOWORD(dwTabExtent);  /* gets width of string    */
wStringHeight = HIWORD(dwTabExtent); /* gets height of string   */

See Also

GetTextExtent, TabbedTextOut