DrawText()

This is a discussion on DrawText() within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I'd like my program to know how much of a given string will fit into a rectangle using DrawText() ...

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

    DrawText()

    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!)

    Cheers,

    dom

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    DT_CALCRECT returns the height of the formatted text. Get the width from the RECT. DT_CALCRECT does not draw the text.
    Code:
    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, 08:21 PM
  2. Printing using DrawText() or TextOut()
    By Eversman in forum Windows Programming
    Replies: 1
    Last Post: 05-24-2004, 01:12 PM
  3. DrawText and different backgounr colors
    By stormbringer in forum Windows Programming
    Replies: 4
    Last Post: 05-09-2003, 04: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

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