M
Maik Wiege
Hi!
I want to show a blinking text over my derived CMDIChildWnd-class. The
blinking is done by one view which is hold by my frame. I set up a timer and
write text to the parent frame, which works fine. But I can't get the text
away the next time the timer fires. Here is some code:
void MyView::OnTimer(UINT nIDEvent)
{
if (nIDEvent!=1) return;
showText = !showText;
// Call base class handler.
CView::OnTimer(nIDEvent);
CUserFrame* frame = (CUserFrame*)(this->GetParentFrame());
CRect clientRect;
frame->GetClientRect(&clientRect);
if (showText){
// display the text --------- THIS WORKS FINE
CFont font;
CDC* dc = frame->GetDC();
font.CreatePointFont (720, _T ("Arial"));
CFont* oldFond = dc->SelectObject (&font);;
dc->SetBkMode (TRANSPARENT);
dc->SetTextColor(RGB(255,100,0));
dc->DrawText(_T("blink"), clientRect, DT_SINGLELINE | DT_CENTER |
DT_VCENTER);
dc->SelectObject (oldFond);
frame->ReleaseDC(dc);
}else{
// remove the text -------------- DOESN'T WORK
// here are many things I tried, but without success
::InvalidateRect(frame->m_hWnd,0,TRUE);
::InvalidateRect(frame->m_hWnd,&clientRect,TRUE);
::UpdateWindow(frame->m_hWnd);
frame->UnlockWindowUpdate();
frame->Invalidate(true);
frame->UpdateWindow();
frame->RedrawWindow();
frame->my2View->UnlockWindowUpdate(); /* my2View is anoter
view that the frame holds (It has a static splitter)*/
frame->my2View->InvalidateRect(&clientRect);
frame->my2View->Invalidate(true);
frame->my2View->UpdateWindow();
frame->my2View->RedrawWindow();
AfxGetMainWnd()->RedrawWindow();
/* To be sure that the code is working corect I added a drawText
here,
which is displayed correctly above the first text and is under
the "blink" after the next timer event */
CDC* dc = frame->GetDC();
dc->DrawText(_T("hello..."), clientRect, DT_SINGLELINE | DT_CENTER |
DT_VCENTER);
frame->ReleaseDC(dc);
}
}
So the result of the above code is that "blink" is written on my window,
then "hello" is written above it, than "blink" again... but the other text
will never be deleted.
Anyone any ideas why this is so, why the window is not redrawn, so the
"blink" should disapear, becaus it is not in the frames OnPaint()?
Thanks for any help
Maik
I want to show a blinking text over my derived CMDIChildWnd-class. The
blinking is done by one view which is hold by my frame. I set up a timer and
write text to the parent frame, which works fine. But I can't get the text
away the next time the timer fires. Here is some code:
void MyView::OnTimer(UINT nIDEvent)
{
if (nIDEvent!=1) return;
showText = !showText;
// Call base class handler.
CView::OnTimer(nIDEvent);
CUserFrame* frame = (CUserFrame*)(this->GetParentFrame());
CRect clientRect;
frame->GetClientRect(&clientRect);
if (showText){
// display the text --------- THIS WORKS FINE
CFont font;
CDC* dc = frame->GetDC();
font.CreatePointFont (720, _T ("Arial"));
CFont* oldFond = dc->SelectObject (&font);;
dc->SetBkMode (TRANSPARENT);
dc->SetTextColor(RGB(255,100,0));
dc->DrawText(_T("blink"), clientRect, DT_SINGLELINE | DT_CENTER |
DT_VCENTER);
dc->SelectObject (oldFond);
frame->ReleaseDC(dc);
}else{
// remove the text -------------- DOESN'T WORK
// here are many things I tried, but without success
::InvalidateRect(frame->m_hWnd,0,TRUE);
::InvalidateRect(frame->m_hWnd,&clientRect,TRUE);
::UpdateWindow(frame->m_hWnd);
frame->UnlockWindowUpdate();
frame->Invalidate(true);
frame->UpdateWindow();
frame->RedrawWindow();
frame->my2View->UnlockWindowUpdate(); /* my2View is anoter
view that the frame holds (It has a static splitter)*/
frame->my2View->InvalidateRect(&clientRect);
frame->my2View->Invalidate(true);
frame->my2View->UpdateWindow();
frame->my2View->RedrawWindow();
AfxGetMainWnd()->RedrawWindow();
/* To be sure that the code is working corect I added a drawText
here,
which is displayed correctly above the first text and is under
the "blink" after the next timer event */
CDC* dc = frame->GetDC();
dc->DrawText(_T("hello..."), clientRect, DT_SINGLELINE | DT_CENTER |
DT_VCENTER);
frame->ReleaseDC(dc);
}
}
So the result of the above code is that "blink" is written on my window,
then "hello" is written above it, than "blink" again... but the other text
will never be deleted.
Anyone any ideas why this is so, why the window is not redrawn, so the
"blink" should disapear, becaus it is not in the frames OnPaint()?
Thanks for any help
Maik