37.1.2 Mouse Capture

The system typically posts a mouse message to the window that contains the mouse-cursor hot spot at the time a mouse event occurs. An application can change this behavior by using the SetCapture function to route mouse messages to a specific window. The window receives all mouse messages until the application calls the ReleaseCapture function or specifies another capture window, or when the user clicks a window created by another thread.

Capturing mouse input is useful if a window needs to receive all mouse input, even when the mouse cursor moves outside the window. For example, an application typically tracks the mouse-cursor position after a mouse “button down” event, following the cursor until a “button up” event occurs. If an application has not captured mouse input and the user releases the mouse button outside the window, the window will not receive the button-up message.

A thread can use the GetCapture function to determine whether one of its windows currently has the mouse captured. If one of the thread's window has captured the mouse, GetCapture retrieves the handle of the window.