Thread: Width of string

  1. #1

    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!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



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, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM