Thread: How to get Text Width and Height?

  1. #1
    Registered User
    Join Date
    Dec 2002

    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 06:40 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    One solution is LOGFONT structure.


  3. #3
    Registered User
    Join Date
    Nov 2002
    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
    Join Date
    Feb 2003
    lesee If I remember right:

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

  5. #5
    train spotter
    Join Date
    Aug 2001
    near a computer
    There is also

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

    which will use the currently selected font (in the hdc) and 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, 06:23 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04: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, 07:35 PM