locked
Scrolling ListView causes a tearing effect at top/bottom RRS feed

  • Question

  • Hello,

    I have a ListView control (SysListView32), which I have set up to do custom drawing by handling CDDS_ITEMPREPAINT. I also handle WM_MOUSEWHEEL to do scrolling by sending LVM_SCROLL.

    When the user scrolls using the mouse wheel, Windows seems to try and do a "smooth scroll" by scrolling the window in a number of small increments.

    The problem is that is does not seem to repaint correctly during this.

    What I have observed is that WM_ERASEBKGND is sent many times during scrolling and a single WM_PAINT happens at the end.
    If I don't do anything in erase-background, then there is a tearing effect as the list moves up/down but no new items are painted to fill the are.
    If I erase the background by simply filling with the background colour, then large scroll movements (such as dragging the scroll bar) have a lot of flickering. Also note that the tearing affect does not happen when using the scroll bar, only scroll wheel.
    Basically what is happening is that the background is showing before a paint event can come along and re-paint the dirty area.

    (Note: I can provide an animation if needed, but with a video is kind of hard to capture what I am seeing)

    Does any one have an explanation for what is going on, or a way to fix it?

    thanks

    Wednesday, March 27, 2019 5:01 AM

Answers

  • Ok, I just fixed the problem!

    Turns out I don't need to specifically handle WM_MOUSEWHEEL, the list view does mouse wheel scrolling itself. I removed the handler for that, and now the behaviour is as I'd expect - for each erase message there is a following paint.


    • Marked as answer by -DavidH- Wednesday, March 27, 2019 5:21 AM
    • Edited by -DavidH- Wednesday, March 27, 2019 5:22 AM
    Wednesday, March 27, 2019 5:13 AM