WinXDraw_GetTextWidth


result = WinXDraw_GetTextWidth (hFont, STRING text, maxWidth)

Gets the width of a string of text, or alternatively, the number of characters that will fit into a certain space

Parameter Description
hFont The handle to the font the text will be drawn with
STRING text The string to test
maxWidth The maximum width for the string

Returns

If the width of the string is < maxWidth, the return value is the width of the string in pixels. If the width of the string > maxWidth the return value is -1*the number of characters that fit in the available space.

Remarks

The height of the text is specified by the font. Because variable pitch fonts have variable character widths and kerning pairs you need this function to calculate the width of a string.

Examples

'how wide is a string?
ret = WinXDraw_GetTextWidth (hFont, "This is a string", 200)
IF ret > 0 THEN
  'ret pixels wide
ELSE
  'too wide
END IF

Related Links

Text and Fonts
WinXDrawText
WinXDraw_GetFontHeight