OnMouseMove Invalidate Paint - uneven paint with multiple views

My application has multiple views, typically four, and some may be hidden.  When the user moves the mouse, I invalidate all the views so changes so changes will be shown in the next Paint event. 

The problem occurs when repainting takes a significant amount of time and the user continues moving the mouse.  The result is that the first view updates rapidly, the rest very slow.

What appears to be happening is subsequent MouseMove events are processed before all views have had a chance to paint.  The first window, which has just finished its paint, finds another paint event in its queue and processes it.  

I have collected statistics on the mouse moves, invalidates, paints to determine that this is (at leas in effect) true.  Is there any way to prevent this effect from occuring  

I can think of a number of hacky solutions which are not desirable, like setting a timer to perform updates.  Counting view paints (and not invalidating until all have been painted) is not an option as they can be hidden or removed, though the result does work.  Perhaps I could post a user message, which I presume will not be recieved untill all controls have handled their events, the goal being to detect a 'loop' in the windows message events and throttle Invalidate calls.



Answer this question

OnMouseMove Invalidate Paint - uneven paint with multiple views

  • Bob__Bob

    I have found what I think is a reasonable solution.  Instead of invalidating the view windows, I Refresh() them, or alternatively Update() them after invalidating.  This causes a syncronous repaint which forces all views to get drawn.  Even if the drawing is slow, windows seems to cull MouseMove events so only one or two are buffered, which is good for the UI.  Clipping is still taken into account, so non-visible or clipped views do not waste time repainting.
  • ron nash

    When the MouseMove actually causes the cursor to move (which occurs constantly when the user moves their mouse at reasonable speed), I need to update multiple 3D views which visualize data and show manipulators.
  • UstesG

    I am interested in why you need to invalidate the views so much. What changes are occurring when the mouse moves that require the views to be invalidated

  • OnMouseMove Invalidate Paint - uneven paint with multiple views