mouse "moves" when it doesn't move

MSDN claims you'll receive WM_MOUSEMOVE when the mouse moves, and that's true as far as it goes. However, you'll also receive WM_MOUSEMOVE at a number of other times, notably when your window activates or another window moving reveals part of yours. So the real meaning of WM_MOUSEMOVE is "please act as if the mouse moved." That's fine most of the time, even though it means you might do some redundant work. But if you really want to know whether the mouse moved, you need to cache the last known mouse location, call GetMessagePos, and compare the result to your cached value. If the mouse really did move, then update your cache in addition to the other work you do.

Update 7 Dec 2006: St. Chen has already covered this topic. Big surprise.

No comments: