2008. 7. 7. 00:49

About Mouse

Mouse Cursor
A single-pixel point called the hot spot, a point that the system tracks and recognizes as the position of the cursor.

The window need not be active or have the keyboard focus to receive a mouse message.

You can use the SystemParametersInfo function with the SPI_GETMOUSE or SPI_SETMOUSE flag to retrieve or set mous speed.

Mouse Capture
An application can chage 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 until the user clicks a window created by another thread.

When the mouse capture changes, the system sends a WM_CAPTUECHANGED message to the window that is losing the mouse capture.

GetCapture
To determine whether one of its window has captured the mouse

Mouse ClickLock
This feature lets a user lock down the primary mouse button after a single click.

Mouse Configuration
An application can determine whether the system includes a mouse by passing the SM_MOUSEPRESENT value to the GetSystemMetrics function

Mouse Messages
The system converts mouse input events into messages and posts them to the appropriate thread's message queue. When mouse message are posted faster than a thread can process them, the system discards all but the most recent mouse message.

Client Area Mouse Messages
An application can call the TrackMouseEvent function to have the system send two other messages. It posts the WM_MOUSEHOVER message when the cursor hovers over the client area for a certain time period. It posts the WM_MOUSELEAVE message when the cursor leaves the client area.

Message Parameters
lParam
Indicates the position of the cursor hot spot. The low-order word indicates the x-coordinate of the hot spot, and the high-order word indicates the y-coordinate. The coordinates are specified in client coordinates.

wParam
Indicates the status of the other mouse buttons and the CTRL and SHIFT keys at the time of the mouse event.
The wParam parameter can be a combination of the following values.
Value Meaning
MK_CONTROL The CTRL key is down.
MK_LBUTTON The left mouse button is down.
MK_MBUTTON The middle mouse button is down.
MK_RBUTTON The right mouse button is down.
MK_SHIFT The SHIFT key is down.
MK_XBUTTON1 Windows 2000/Windows XP: the first X button is down.
MK_XBUTTON2 Windows 2000/Windows XP: the second X button is down.


Double-Click Messages
The system generates a double-click message when the user clicks a mouse button twice in quick succession.
When the user clicks a button, the system establishes a rectangle centered around the cursor hot spot. It also marks the time at which the click occurred.
When the user clicks the same button a second time, the system determines whether the hot spot is still within the rectangle and calculates the time elapsed since the first click.
If the hot spot is still within the rectangle and the elapsed time does not exceed the double-click time-out value, the system generates a double-click message.

An application can get and set double-click time-out values by using the GetDoubleClickTime and SetDoubleClickTime functions,
Alternatively the application can set the double-click-time-out-value by using the SPI_SETDOUBLECLICKTIME flag with the SystemParametersInfo function. It can also set te size of the rectangle that the system uses to detect double clicks by passing the SPI_SETDOUBLECLKWIDTH and SPI_SETDOUBLECLKHEIGHT flags to SystemParametersInfo.
Note, however, that setting the double-click-time-out vlaue and rectangle affects all applications.

An application-defined window does not, by default, receive double-click messages. Because of the system overhead involved in generating double-click messages, these messages are gnerated only for windows belonging to classes that have the CS_DBLCLKS class style.

A double-click message is always the third message in a four-message series.
For example, double-clicking the left mouse button generates the following message sequences:

1. WM_LBUTTONDOWN
2. WM_LBUTTONUP
3. WM_LBUTTONDBLCLK
4. WM_LBUTTONUP

Because a window always receives a button-down message before receiving a double-click message, an application typically uses a double-click message to extend a task it began during a button-down message.

Nonclient Area Mouse Messages
A window's nonclient area consists of its border, menu bar, title bar, scroll bar, window menu, minimize button, and maximize button.

A window must pass nonclient area mouse message to the DefWindowProc function to take advantage of the built-in mouse interface.

There is a corresponding nonclient area mouse message for each client area mouse message.

lParam
Unlike coordinates of client area mouse messages, the coordinaes are specified in screen coordinates rather than client coordinates.

wParam
contains a hit-test value, a value that indicates where in the nonclient area the mouse event occurred.

The WM_NCHITTEST Message
Whenever a mouse event occurs, the system sends a WM_NCHITTEST message to either the window that contains the cursor hot spot or the window that has captured the mouse. The system uses this message to determine whether to send a client area or nonclient area mouse message.
An application that must receive mouse movement and mouse button messages must pass the WM_NCHITTEST message to the DefWindowProc function.

The lParam parameter of the WM_NCHITTEST message contains the screen coordinates of the cursor hot spot. The DefWindowProc function examines the coordinates and returns a hit-test value that indicates the location of the hot spot. Te hit-test value can be one of the following values.

Value Location of hot spot
HTBORDER                                        In the border of a window that does not have a sizing border.
HTBOTTOM In the lower-horizontal border of a window.
HTBOTTOMLEFT In the lower-left corner of a window border.
HTBOTTOMRIGHT In the lower-right corner of a window border.
HTCAPTION In a title bar.
HTCLIENT In a client area.
HTCLOSE In a Close button.
HTERROR On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error).
HTGROWBOX In a size box (same as HTSIZE).
HTHELP In a Help button.
HTHSCROLL In a horizontal scroll bar.
HTLEFT In the left border of a window.
HTMENU In a menu.
HTMAXBUTTON In a Maximize button.
HTMINBUTTON In a Minimize button.
HTNOWHERE On the screen background or on a dividing line between windows.
HTREDUCE In a Minimize button.
HTRIGHT In the right border of a window.
HTSIZE In a size box (same as HTGROWBOX).
HTSYSMENU In a System menu or in a Close button in a child window.
HTTOP In the upper-horizontal border of a window.
HTTOPLEFT In the upper-left corner of a window border.
HTTOPRIGHT In the upper-right corner of a window border.
HTTRANSPARENT In a window currently covered by another window in the same thread.
HTVSCROLL In the vertical scroll bar.
HTZOOM In a Maximize button.

Mouse Sonar
This feature briefly shows several concentric circles around the pointer when the user presses and releases the CTRL key.

SystemPrametersInfo
SPI_GETMOUSESONAR
SPI_SETMOUSESONAR

Mouse Vanish
This feature hides the pointer when the user is typing. The mouse pointer reappears when the user moves the mouse.

SstemParametersInfo
SPI_GETMOUSEVANISH
SPI_SETMOUSEVANISH

The Mouse Wheel
When an application processes the WM_MOUSEWHEEL message, it must return zero. When an application processes the MSH_MOUSEWHEEL message, it must return TRUE.

Detecting a Mouse with a Wheel
To determine if a mouse with a wheel is connected, call GetSystemMetrics(SM_MOUSEWHEELPRESENT)

ClipCursor()
To confine the cursor to the client area during the line drawing operation.

Processing a Double Click Message
To receive double-click messages, a window must belong to a window class that has the CS_DBLCLKS class style.