User input can also come from the mouse. Windows sends mouse-input messages to the application when the user moves the cursor into and through a window or presses or releases a mouse button while the cursor is in the window. Windows generates mouse-input messages in response to the following events:
Message | Event |
WM_MOUSEMOVE | User moves the cursor into or through the window. |
WM_LBUTTONDOWN | User presses the left button. |
WM_LBUTTONUP | User releases the left button. |
WM_LBUTTONDBLCLK | User presses, releases, and presses again the left button within the system's defined double-click time. |
WM_MBUTTONDOWN | User presses the middle button. |
WM_MBUTTONUP | User releases the middle button. |
WM_MBUTTONDBLCLK | User presses, releases, and presses again the middle button within the system's defined double-click time. |
WM_RBUTTONDOWN | User presses the right button. |
WM_RBUTTONUP | User releases the right button. |
WM_RBUTTONDBLCLK | User presses, releases, and presses again the right button within the system's defined double-click time. |
The wParam parameter corresponding to each button pressed or released includes a bitmask specifying the current state of the keyboard and mouse buttons, such as whether the mouse buttons, SHIFT key, and CTRL key are down. The lParam parameter contains the x- and y-coordinates of the cursor.
Windows sends mouse-input messages to a window only if the cursor is in the window or if your application has captured mouse input by using the SetCapture function. This function directs Windows to send all mouse input, regardless of where the cursor is, to the specified window. Applications typically use this function to take control of the mouse when carrying out some critical operation with the mouse, such as selecting something in the client area. Capturing mouse input prevents other applications from taking control of the mouse before the operation is completed.
Since the mouse is a shared resource, it is important for an application to release the captured mouse as soon as it has finished the operation. The application can release the mouse by using the ReleaseCapture function; it can also determine which window, if any, has captured the mouse, by using the GetCapture function.
Windows sends double-click messages to a window procedure only if the corresponding window class has the CS_DBLCLKS style. Your application must set this style when registering the window class. A double-click message is always the third message in a four-message series. The first two messages are the first button press and release. The second button press is replaced with the double-click message. The last message is the second release. Remember that a double-click message occurs only if the first press and the second press occur within the system's defined double-click time. The application can retrieve the current double-click time by using the GetDoubleClickTime function, and it can set it by using the SetDoubleClickTime function (this sets the double-click time for all applications, not just your own).