Finding the length of text with an API function
Is there an API function which will tell how long (in pixels) a certain amount of text is? I’m writing a status bar control and want the user to be able to know how much space is required for their status text. I though I remember using an API function to do this before, but for the life of me can’t find a function which would do this. Can anyone tell me either which function it is or else let me know that in fact I simply not remember correctly? Thanks.
Mike
Re: Finding the length of text with an API function
public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (byval hdc as Long, byval lpsz as string, byval cbString as Long, lpSize as POINTAPI) as Long
'
public Type POINTAPI
X as Long ' Character Height
Y as Long ' Width of string
End Type
'
public TextSize as POINTAPI
'
GetTextExtentPoint32 ndc, tx, len(tx), TextSize
' ncd is the hdc of the container for the text
' tx is the string to analyze
' textsize structure is returned values (see comments)
John G
Re: Finding the length of text with an API function
you can use:
me.ScaleMode = vbPixels
a = me.TextHeight(s)
b = me.TextWidth(s)
l=a*b
I haven't checked that but it should work.
You can play with it as you wish.
----------
The @host is everywhere!
----------