CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Posts
    731

    DrawText() does not draw

    If i do pDC->Rectangle(rc); it draws the rectangle correctly where I want to draw the text.

    I want to draw text inside this rectangle, it does not draw text (with or without caling Rectangle() function)
    Code:
    pDC->DrawText("Hello", rc, DT_SINGLELINE | DT_LEFT);
    This is not working in the first place and my goal is draw the text right aligned.
    Good Answers, Good Points.

  2. #2
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: DrawText() does not draw

    What is the text color? Perhaps you are drawing white on white ( or black on black etc).
    Har Har

  3. #3
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: DrawText() does not draw

    Are you drawing the text or the rect first ?
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  4. #4
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: DrawText() does not draw

    Perhaps you should try this
    Code:
    	CRect rect(50,60,0,0); //in this case is not a normal rect :)
    	rect.NormalizeRect();
    	pDC.DrawText("Hello",rect, DT_SINGLELINE | DT_LEFT);

  5. #5
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: DrawText() does not draw

    Quote Originally Posted by retry
    Code:
    pDC->DrawText("Hello", rc, DT_SINGLELINE | DT_LEFT);
    This is not working in the first place and my goal is draw the text right aligned.
    You must use "DT_RIGHT" if you want to right align the text...not "DT_LEFT". At what X-Y position are you trying to draw the text...do you have a MoveTo function call before calling DrawText ?? Can you use TextOut and supply the location of the Text to be printed within the TextOut function call.
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  6. #6
    Join Date
    Jul 2003
    Posts
    731

    Re: DrawText() does not draw

    The points go to g_gili, NormalizeRect() rect fixes the problem.

    Sometimes these things are now documented in MSDN that the rect should be normalized before calling DrawText()...can anybody shine light why we need to NormalizeRect()?
    Good Answers, Good Points.

  7. #7
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: DrawText() does not draw

    At the NormalizeRect
    The following CRect methods require normalized rectangles in order to work properly
    ....
    Width

    So I think when you use DrawText() then you have to normalize first the rectangle if you have to that means if (x1>x2 or y1>y2)
    Code:
    CRect rect(50,60,0,0);//in this case the Width() = - 50  at the default maping mode
    So I think you can't draw the text when your rectangle width is a negative number .
    Last edited by g_gili; April 11th, 2006 at 01:29 PM.
    Please use code tags [code] [/code]

    We would change the world, but God won't give us the sourcecode..
    Undocumented futures are fun and useful....
    ___
    ______
    Gili

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured