Results 1 to 4 of 4

Thread: Width of text...

  1. #1
    amac
    Guest

    Post Width of text...

    How can I find the width of a string...

    So if i had.

    "This is the text that would be in a text box."

    How can I create a RECT that would have the width and height of this string.

    Thanx

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    GetExtentPoint32(HDC, LPCTSTR, UINT, PSIZE)
    You supply the device context, the string, it's length and a SIZE variable that is filled with the size of the string with the current settings (font, font size etc.).

    In MFC it is called GetTextExtent
    Code:
    CSize CDC::GetTextExtent(LPTSTR, UINT);
    CSize CDC::GetTextExtent(CString&);
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    jim mcnamara
    Guest
    The MFC CDC:: method I knew about. But I like the idea of GetExtentPoint32 better - with ONE big problem.

    I can't find it at MSDN, or in my version of api toolshed. Did you misspell the api by some chance? Or maybe I can't type....

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, I misspelled it. Of course it's GetTextExtentPoint32 (like GetTextExtent in MFC)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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