Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems getting CStatic to refresh

0 views
Skip to first unread message

Eddie

unread,
May 9, 2005, 11:45:47 AM5/9/05
to
Hi,

I'm having problems trying to update the contents a CStatic control
that exists in a SDI application. Whenever I try to update the control,
the new text appears to sit on top of the existing text. It seems that
the control does not get refreshed after the call to SetWindowText(). I
have tried calling CStatic::Invalidate() and CStatic::RedrawWindow()
directly but nothing seems to work.

My only solution is to call CView::Invalidate() every couple of
seconds, but this causes a very anoying flicker. Here is the call to
CStatic::Create(). Maybe I'm missing something? Any help would be
appreciated.

VERIFY(m_LoadTitleTxt.Create(szTemp, WS_CHILD | WS_VISIBLE,
CRect(10,10,130,30), this));

Thanks
Eddie.

Doug Harrison [MVP]

unread,
May 9, 2005, 12:21:30 PM5/9/05
to
On 9 May 2005 08:45:47 -0700, Eddie wrote:

> Hi,
>
> I'm having problems trying to update the contents a CStatic control
> that exists in a SDI application. Whenever I try to update the control,
> the new text appears to sit on top of the existing text. It seems that
> the control does not get refreshed after the call to SetWindowText(). I
> have tried calling CStatic::Invalidate() and CStatic::RedrawWindow()
> directly but nothing seems to work.
>
> My only solution is to call CView::Invalidate() every couple of
> seconds, but this causes a very anoying flicker. Here is the call to
> CStatic::Create(). Maybe I'm missing something? Any help would be
> appreciated.

I think your parent window need to handle WM_CTLCOLORSTATIC. In MFC, see
OnCtlColor:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.onctlcolor.asp

> VERIFY(m_LoadTitleTxt.Create(szTemp, WS_CHILD | WS_VISIBLE,
> CRect(10,10,130,30), this));

FWIW, I've always had misgivings about the VERIFY macro. For something that
can legitimately fail at runtime due to forces beyond your control, it
seems to me you should handle the error. That is, the successful execution
of your Create call in debug mode does not necessarily imply successful
execution in release mode, so checking it with VERIFY is thus rather bogus,
IMO.

--
Doug Harrison
Microsoft MVP - Visual C++

RainMan

unread,
May 9, 2005, 3:50:01 PM5/9/05
to
Is static control part of dialog resource used by CFormView derived class or
you embed it in another CView derived?
Could you post more details?

Naren

unread,
May 10, 2005, 2:44:01 AM5/10/05
to
hi,
i worked on the sample dialog applicaton, and it is refreshing properly. BUt
i got the same kind of problem when developing one application for my
company. At that time becasue of timely deadlines i couldn;t look on that
more. To get the quilk solution what i did was i invalidated the view, and in
the onpaint of that view i manually refreshed the previous content of static
control. If i came to know the solution, i ll let u know

naren

0 new messages