CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2001
    Posts
    20

    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


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    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

  3. #3
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    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!
    ----------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured