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.
Printable View
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.
Put the code in OnPaint()
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 ...Quote:
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.
Just use class wizard to create a message handler for WM_PAINT, then stick the code in there
If I use CStatic instead of pDC->DrawText, there is no need to add codes in OnPaint(). Why??
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.
<good answer Eli>
Thanks guys. Appreciate your answers.
You can as well insert the line
pDC->DrawText(str, 20, myRect, DT_RIGHT);
in the OnDraw function of your CView derived class
regards
All these references to CView. He never once said he's using doc/view. It might just be a dlg guys ...
Yes, I am using doc/view. But it is also interesting to see how it can be handled in non-doc/view application.
The implementation is the same in either case.
I redraw in the OnPaint function. It works. Thanks.
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);
}
IThe 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.Code:HBRUSH hbr = CreateSolidBrush(RGB(0,0,0));
pDC->FillRect(myRect, &hbr);
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.