GetTextMetrics

2.x

  BOOL GetTextMetrics(hdc, lptm)    
  HDC hdc; /* handle of device context */
  TEXTMETRIC FAR* lptm; /* pointer to structure for font metrics */

The GetTextMetrics function retrieves the metrics for the current font.

Parameters

hdc

Identifies the device context.

lptm

Points to the TEXTMETRIC structure that receives the metrics. The TEXTMETRIC structure has the following form:

typedef struct tagTEXTMETRIC {  /* tm */
    int  tmHeight;
    int  tmAscent;
    int  tmDescent;
    int  tmInternalLeading;
    int  tmExternalLeading;
    int  tmAveCharWidth;
    int  tmMaxCharWidth;
    int  tmWeight;
    BYTE tmItalic;
    BYTE tmUnderlined;
    BYTE tmStruckOut;
    BYTE tmFirstChar;
    BYTE tmLastChar;
    BYTE tmDefaultChar;
    BYTE tmBreakChar;
    BYTE tmPitchAndFamily;
    BYTE tmCharSet;


    int  tmOverhang;
    int  tmDigitizedAspectX;
    int  tmDigitizedAspectY;
} TEXTMETRIC;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value is nonzero if the function is successful. Otherwise, it is zero.

Example

The following example calls the GetTextMetrics function and then uses information in a TEXTMETRIC structure to determine how many break characters are in a string of text:

TEXTMETRIC tm;
int j, cBreakChars, cchString;
LPSTR lpszJustified = "Text to be justified in this test.";

GetTextMetrics(hdc, &tm);

cchString = lstrlen(lpszJustified);

for (cBreakChars = 0, j = 0; j < cchString; j++)
    if(*(lpszJustified + j) == (char) tm.tmBreakChar)
        cBreakChars++;

See Also

GetTextAlign, GetTextExtent, GetTextFace, SetTextJustification