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

    Retain text display

    I am using pDC->DrawText(str, 20, myRect, DT_RIGHT); to display text in str.
    After the window is minimized or another window is on top of it, the text disappears.
    What should be done to retain the text display? Thanks in advance for your help.

  2. #2
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Put the code in OnPaint()

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  3. #3
    Join Date
    Mar 2001
    Posts
    168
    You need to put the line
    pDC->DrawText(str, 20, myRect, DT_RIGHT);
    in the OnPaint function of your CView derived class. Only there will it be redrawn.

  4. #4
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Originally posted by rsmemphis
    You need to put the line
    pDC->DrawText(str, 20, myRect, DT_RIGHT);
    in the OnPaint function of your CView derived class. Only there will it be redrawn.
    Might not be a CView, could be a CWnd ...

    Just use class wizard to create a message handler for WM_PAINT, then stick the code in there

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  5. #5
    Join Date
    Jul 2001
    Posts
    132
    If I use CStatic instead of pDC->DrawText, there is no need to add codes in OnPaint(). Why??

  6. #6
    Join Date
    Apr 2002
    Location
    PA, USA
    Posts
    1,658
    CStatic is a static text control, based on a CWnd, so when it gets invalidated, it calls its own redraw function. A radio button, a push button -- all those controls -- are CWnd's that have their own draw/paint routines built into them. When you are drawing lines, though, your application doesn't know if you want them to stay or not when it gets invalidated, because those lines aren't typically there! Taht's why you have to add them yourself to the paint/draw proceedure.
    =--=--=--=--=--=--=--=--=--=--=--=--=--=
    Please rate this post to show your appreciation for those that helped you.

    Before You Post A Question, Please Read This: How & When To Ask Your Question
    =--=--=--=--=--=--=--=--=--=--=--=--=--=

    -eli
    http://www.toad-software.com
    http://www.dailymission.com - Do It Daily

  7. #7
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    <good answer Eli>

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  8. #8
    Join Date
    Jul 2001
    Posts
    132
    Thanks guys. Appreciate your answers.

  9. #9
    Join Date
    May 2003
    Posts
    4

    Thumbs up

    You can as well insert the line
    pDC->DrawText(str, 20, myRect, DT_RIGHT);
    in the OnDraw function of your CView derived class
    regards

  10. #10
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    All these references to CView. He never once said he's using doc/view. It might just be a dlg guys ...

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  11. #11
    Join Date
    Jul 2001
    Posts
    132
    Yes, I am using doc/view. But it is also interesting to see how it can be handled in non-doc/view application.

  12. #12
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    The implementation is the same in either case.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  13. #13
    Join Date
    Jul 2001
    Posts
    132
    I redraw in the OnPaint function. It works. Thanks.

  14. #14
    Join Date
    Jul 2001
    Posts
    132
    Hi all,

    Another interesting problem I have with DrawText in TRANSPARENT background mode is that when I use DrawText with pDC->SetBkMode(TRANSPRENT) to update a number value stored in CString str, the new number will display on top of the previous displayed numbers. What should I do to clear the area of myRect before display the new number?

    Example to illustrate my question:
    ...
    pDC->SetBkMode(TRANSPARENT);
    for (int number=0; number<100; number++)
    {
    str.Format("%i", number);
    pDC->DrawText(str, 20, myRect, DT_RIGHT);
    }

  15. #15
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    I
    Code:
    HBRUSH hbr = CreateSolidBrush(RGB(0,0,0)); 
    pDC->FillRect(myRect, &hbr);
    The RGB value should bve your background color. If you have no control over the background color because it is a windows config specific color, then you can use GetSysColor() to retrieve the RGB you need. This will fill clear the area specified by rect with the background color.

    Now redraw your text ...

    If your background is not a solid color, such as a bitmap, you will need to redraw the bitmap, then the text.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

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