Receive user input

Source: Internet
Author: User

 

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)
  <

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.