Thread: Measure text according to font

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    Measure text according to font

    Say I create a font like so.

    Code:
    	HFONT font = CreateFont(f_height,f_width,0,0,f_weight,f_italic,
    				f_underline,f_strike,f_charset,OUT_TT_PRECIS,
    				CLIP_DEFAULT_PRECIS,f_quality,
    				FF_DONTCARE|DEFAULT_PITCH,font_name.c_str());
    	SelectObject(hdc, font);
    Pretend like everything works and is defined.

    Now, how do I figure out the unit length of a text string displayed with that font? Ive been looking for hours for a library function that dose that, and all I have found is Graphics.MeasureString from the .NET framework. But I am not using .NET.
    Last edited by Eber Kain; 11-04-2005 at 05:49 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    I knew there was a library function out there, but damned if I could find it.

    Thanks alot man.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you use

    DrawText()

    then first use DT_CALCRECT to get the size.
    "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. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. 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
  4. Changing the font on static text and buttons
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 06-28-2002, 09:36 AM
  5. Font and text type
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 02-02-2002, 12:33 PM