Receive mouse input in view:
A mouse message is a message that we often need to process. messages are divided into: move the mouse, and press the button/Release, double-click. With ClassWizard, you can easily add these message mappings. The following describes how to process each message.
The function corresponding to WM_MOUSEMOVE is OnMouseMove (UINT nFlags, CPoint point). nFlags indicates the messages of some buttons currently. You can perform detection through the bitwise AND operation.
- MK_CONTROLWhether the Ctrl key is Set if the CTRL key is down.
- MK_LBUTTONWhether the left mouse button is pressed Set if the left mouse button is down.
- MK_MBUTTONWhether the intermediate mouse key is Set if the middle mouse button is down.
- MK_RBUTTONRight-click whether Set if the right mouse button is down.
- MK_SHIFTWhether the Shift key is Set if the SHIFT key is down.
Point indicatesDevice coordinates, The coordinate origin corresponds to the upper left corner.
The corresponding function of WM_LBUTTONDOWN/WM_RBUTTONDOWN (left/right-click) is OnLButtonDown/OnRButtonDown (UINT nFlags, CPoint point), which has the same meaning as OnMouseMove.
The OnLButtonUp/OnRButtonUp (UINT nFlags, CPoint point) parameter corresponds to the WM_LBUTTONUP/WM_RBUTTONUP (left/right-click release) function.
The corresponding function of WM_LBUTTONDBLCLK/WM_RBUTTONDBLCLK (left/right-click) is OnLButtonDblClk/OnRButtonDblClk (UINT nFlags, CPoint point), which is the same as OnMouseMove.
Below I will use a piece of pseudo code to explain the usage of these messages:
The purpose of the code is to pull a rectangle with the mouse
Global BOOL fDowned; // whether to pull
Global CPoint ptDown; // click the position
Global CPoint ptUp; // release location
OnLButtonDown (UINT nFlags, CPoint point)
{
FDowned = TRUE;
PtUp = ptDown = point;
DrawRect ();
...
}
OnMouseMove (UINT nFlags, CPoint point)
{
If (fDowned)
<