Thread: DrawText()

  1. #1
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002


    Hi, I'd like my program to know how much of a given string will fit into a rectangle using DrawText() so that it knows when to create a new 'page' so to speak.

    Is this possible or will I have to use something else. (hope it makes any kinda sense!)



  2. #2
    Registered User
    Join Date
    Mar 2003
    DT_CALCRECT returns the height of the formatted text. Get the width from the RECT. DT_CALCRECT does not draw the text.
    CString strText = _T("Your line of text");
    RECT rectDummy = {0,0,0,0};
    int nHeight = pDC->DrawText(strText, -1, &rectDummy, DT_TOP | DT_SINGLELINE | DT_CALCRECT);
    int nWidth  = rectDummy.right - rectDummy.left;
    Last edited by Scarlet7; 04-03-2003 at 03:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with DrawText (DirectX9)
    By Diod in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2006, 07:21 PM
  2. Printing using DrawText() or TextOut()
    By Eversman in forum Windows Programming
    Replies: 1
    Last Post: 05-24-2004, 12:12 PM
  3. DrawText and different backgounr colors
    By stormbringer in forum Windows Programming
    Replies: 4
    Last Post: 05-09-2003, 03:34 AM
  4. DrawText() and TextOut() newbie question
    By Cardassian in forum Windows Programming
    Replies: 3
    Last Post: 02-23-2003, 10:09 AM
  5. DrawText and backgrounds c++
    By AtomRiot in forum Windows Programming
    Replies: 1
    Last Post: 01-04-2003, 03:10 AM