Discussion:
CListCtrl update data, how to avoid flicker
(too old to reply)
huanjie liu
2015-11-11 09:26:07 UTC
Permalink
Hi, I have a list, which is report mode, and I have to update data every 5 seconds. The problem is when I update data and display them with SetItemText function, it is flickering.
How can I avoid this, I've tried SetRedraw(FALSE), ShowWindow(SW_HIDE), LockWindowUpdate() and SendMessage function, but still don't work.
Can someone help ? Thanks in advance.
David Lowndes
2015-11-11 10:19:30 UTC
Permalink
Post by huanjie liu
Hi, I have a list, which is report mode, and I have to update data every 5 seconds. The problem is when I update data and display them with SetItemText function, it is flickering.
How can I avoid this, I've tried SetRedraw(FALSE), ShowWindow(SW_HIDE), LockWindowUpdate() and SendMessage function, but still don't work.
LockWindowUpdate() isn't intended for general application use. The
recommended method is to use SetRedraw. See the example here:
https://msdn.microsoft.com/en-us/library/btaacw58.aspx and read this
article:
http://blogs.msdn.com/b/oldnewthing/archive/2011/01/24/10119211.aspx

Dave
huanjie liu
2015-11-11 10:41:50 UTC
Permalink
在 2015年11月11日星期三 UTC+8下午6:19:36,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
Hi, I have a list, which is report mode, and I have to update data every 5 seconds. The problem is when I update data and display them with SetItemText function, it is flickering.
How can I avoid this, I've tried SetRedraw(FALSE), ShowWindow(SW_HIDE), LockWindowUpdate() and SendMessage function, but still don't work.
LockWindowUpdate() isn't intended for general application use. The
https://msdn.microsoft.com/en-us/library/btaacw58.aspx and read this
http://blogs.msdn.com/b/oldnewthing/archive/2011/01/24/10119211.aspx
Dave
Hello Dave,
Should I implement CustomRedraw myself ? just SetRedraw(FALSE) and then SetRedraw(TRUE) doesn't works.
Thanks
David Lowndes
2015-11-11 13:47:47 UTC
Permalink
Post by huanjie liu
Should I implement CustomRedraw myself ? just SetRedraw(FALSE) and then SetRedraw(TRUE) doesn't works.
When you say SetRedraw doesn't work, does it do nothing different to
not having it, or does it not do quite what you expect?

Dave
huanjie liu
2015-11-12 00:48:00 UTC
Permalink
在 2015年11月11日星期三 UTC+8下午9:47:54,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
Should I implement CustomRedraw myself ? just SetRedraw(FALSE) and then SetRedraw(TRUE) doesn't works.
When you say SetRedraw doesn't work, does it do nothing different to
not having it, or does it not do quite what you expect?
Dave
Nothing different to not having it.
David Lowndes
2015-11-12 09:32:55 UTC
Permalink
Post by huanjie liu
Post by David Lowndes
When you say SetRedraw doesn't work, does it do nothing different to
not having it, or does it not do quite what you expect?
Nothing different to not having it.
Is there any custom code involved in drawing the listview?
Can you reproduce this behaviour in a trivial example application?

Dave
huanjie liu
2015-11-13 04:30:25 UTC
Permalink
在 2015年11月12日星期四 UTC+8下午5:33:03,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
Post by David Lowndes
When you say SetRedraw doesn't work, does it do nothing different to
not having it, or does it not do quite what you expect?
Nothing different to not having it.
Is there any custom code involved in drawing the listview?
Can you reproduce this behaviour in a trivial example application?
Yep, I use custom draw to set the item color, add a customlist function which handles the NM_CUSTOMDRAW message.
And I have a timer, every 5 seconds I update the data, and then setitemtext update the list. But it still flickers when I add SetRedraw functions.
Post by David Lowndes
Dave
And thanks for your reply, Dave ;)
David Lowndes
2015-11-13 08:43:40 UTC
Permalink
Post by huanjie liu
Yep, I use custom draw to set the item color, add a customlist function which handles the NM_CUSTOMDRAW message.
So, does SetRedraw remove the flicker if you don't do your custom
drawing?

Dave
huanjie liu
2015-11-13 08:46:21 UTC
Permalink
在 2015年11月13日星期五 UTC+8下午4:43:48,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
Yep, I use custom draw to set the item color, add a customlist function which handles the NM_CUSTOMDRAW message.
So, does SetRedraw remove the flicker if you don't do your custom
drawing?
Dave
Let me try, but I have to user custom drawing ->_->
huanjie liu
2015-11-13 08:49:10 UTC
Permalink
在 2015年11月13日星期五 UTC+8下午4:46:26,huanjie liu写道:
Post by huanjie liu
在 2015年11月13日星期五 UTC+8下午4:43:48,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
Yep, I use custom draw to set the item color, add a customlist function which handles the NM_CUSTOMDRAW message.
So, does SetRedraw remove the flicker if you don't do your custom
drawing?
Dave
Let me try, but I have to user custom drawing ->_->
it removes the flicker, even I don't use Redraw function! But now the problem is, how can I remove flicker with custom drawing ?
David Lowndes
2015-11-13 10:50:40 UTC
Permalink
Post by huanjie liu
it removes the flicker, even I don't use Redraw function! But now the problem is, how can I remove flicker with custom drawing ?
I suspect then that your custom drawing is still being called even
after you try to inhibit drawing by using SetRedraw.

If that is the case, the solution would be to handle the SetRedraw
message (WM_SETREDRAW) in a derived CListCtrl class and have your own
flag to prevent you doing your custom drawing code while the flag is
set.

Dave
huanjie liu
2015-11-13 15:57:16 UTC
Permalink
在 2015年11月13日星期五 UTC+8下午6:50:44,David Lowndes写道:
Post by David Lowndes
Post by huanjie liu
it removes the flicker, even I don't use Redraw function! But now the problem is, how can I remove flicker with custom drawing ?
I suspect then that your custom drawing is still being called even
after you try to inhibit drawing by using SetRedraw.
If that is the case, the solution would be to handle the SetRedraw
message (WM_SETREDRAW) in a derived CListCtrl class and have your own
flag to prevent you doing your custom drawing code while the flag is
set.
Dave
OK, thanks a lot, Dave.
It is the problem of custom drawing, and I modified the custom draw function,
now it is almost not flikering.

Loading...