How to get Text Width and Height?

This is a discussion on How to get Text Width and Height? within the Windows Programming forums, part of the Platform Specific Boards category; Hi, all How do you get the exact width and height (even if the user has increased or decreased the ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    162

    Unhappy How to get Text Width and Height?

    Hi, all

    How do you get the exact width and height (even if the user has increased or decreased the DPI settings) of a single-font multi-line text without drawing it? Do you use GetCharWidth32 for this process or are there better ways? Could you please demonstrate this process in code please =)
    Last edited by Aidman; 03-02-2003 at 05:40 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is LOGFONT structure.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    i think you can do something like GetDialogBaseUnits and take the hiword and loword of that to get x and y heights and widths of those.

  4. #4
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    lesee If I remember right:

    Code:
    TEXTMETRIC tm;
    
    int xchar,ychar; // to store the values
    
    xchar = tm.tmAveCharWidth;
    ychar = tm.tmAveCharHeight + tm.tmExternalLeading;

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    There is also

    GetTextExtentPoint32(hdc , sBuffer, lstrlen(sBuffer), &Size);

    which will use the currently selected font (in the hdc)

    Size.cx and Size.cy contain the strings (sBuffer) length and width.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21