Width of string

This is a discussion on Width of string within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to find the width of a string. I've tried using GetTextMetrics and multiplying the vaerage character with by ...

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    Width of string

    I'm trying to find the width of a string. I've tried using GetTextMetrics and multiplying the vaerage character with by the length returned from lstrlen but to no avail.

    I also tried using DrawText with DT_CALCRECT but that didn't seem to work at all..

    [edit:] Actually DT_CALCRECT was working, I forgot to add the 18px I was adding to the left side to bump it over a litle..
    Last edited by Mithoric; 05-01-2004 at 02:33 AM.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    23
    This should help:

    SIZE txtSize;

    GetTextExtentPoint32 (hdc, theText, strlen(theText), &txtSize);

    Then use txtSize.cx an txtSize.cy

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Awesome this is the exact answer I was just looking for!
    "A government big enough to give you everything you want, is big enough to take away everything you have." - Thomas Jefferson
    MSVS 2008 Pro / DevPartner / CB NightlyBuilds / MinGW / Cygwin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 10:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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