LockerGnomeTech news and nostalgia for today's technology professionals
Subscribe

Search

Software

Windows Fakes Mouse Movement Just to Swap Your Pointer Icon, Firing Phantom WM_MOUSEMOVE Events

Microsoft veteran Raymond Chen explained how showing, hiding, or shifting a window trips an internal input flag, forcing developers to verify coordinates manually.

Chris Pirillo as a plastic brick-toy figure in glasses, smiling wryly beside a brick-built computer window where a sliding dialog box passes under a pixel cursor and sets off a red Mouse Moved flag and a stack of WM_MOUSEMOVE message tiles.
Illustration: LockerGnome

To understand why Windows lies about your mouse moving, look at how the operating system handles a real hardware nudge. When a physical mouse fires an interrupt, Windows figures out which thread owns that screen area and sets a single flag on the thread’s input queue. As Raymond Chen put it in his October 1, 2003 write-up on The Old New Thing, that flag effectively says, “The mouse moved, in case anybody cares.”

Nothing else happens until the receiving thread checks its mail by calling a message-retrieval function like GetMessage. Only then does Windows inspect the pointer coordinates, pick the target window, update the pointer graphic, and decide whether to generate WM_MOUSEMOVE or WM_NCMOUSEMOVE. That lazy-flag architecture also explains why sluggish programs miss rapid hand movements: if two hardware interrupts arrive before your code calls GetMessage, the second interrupt merely sets a flag that is already set. The first interrupt acts as if it were “lost” because nobody bothered to pick it up.

It also means Windows delivers mouse movement messages “as fast as you want,” paced strictly by how often your loop asks for them. Every piece of follow-on housekeeping tied to pointer movement lives behind that one flag, including figuring out what icon the user should see. And that is where OS thriftiness kicks in (because why write two paths?). When a window is shown, hidden, or moved while your hand sits nowhere near the desk, the stationary pointer may suddenly hover over a different window—or a different part of the same one.

Suppose the old window wanted a standard arrow while the newly uncovered surface wants a pointy finger. Windows has to recalculate the pointer icon, and all of the machinery for that job already sits inside the mouse-movement pipeline. Rather than duplicating the plumbing, Windows artificially sets the “The mouse moved, in case anybody cares” flag on its own—crying mouse just to swap an arrow for a hand. All the usual follow-on work executes on cue, and your application catches a brand-new, completely spurious WM_MOUSEMOVE message for a device that never budged a millimeter.

That shortcut is pure systems-engineering pragmatism—and a reminder that operating system messages rarely mean what their names promise on the tin. Reusing the mouse-move flag saved Windows from maintaining a parallel pointer-refresh path every time window layering changed (sorry, idle timers). For the window manager, firing an extra message costs next to nothing; for the developer wiring up a custom hover state or activity check, it is a quiet trap waiting to spring years down the road.

Chen has been involved in the evolution of Windows for more than 30 years, and his 2003 note still reads like a survival guide for anyone maintaining desktop software. Core message-loop quirks tend to outlive the hardware they were designed around, because altering them risks breaking decades of applications that lean on the side effect. The pointer changes; the mouse never budged.

More Software

Every Software story →