Windows program design Reading Notes-mouse.

Source: Internet
Author: User

I. Detect the mouse:

Determine if a mouse exists: getsystemmetrics (sm_mousepresent); // valid after Windows98

Determine the mouse keys: getsystemmetrics (sm_cmousebuttons); // valid after Windows98

 

2. A total of 21 mouse messages:

Customer zone message

# Define wm_mousemove 0x0200
# Define wm_lbuttondown 0x0201
# Define wm_lbuttonup 0x0202
# Define wm_lbuttondblclk 0x0203
# Define wm_rbuttondown 0x0204
# Define wm_rbuttonup 0x0205
# Define wm_rbuttondblclk 0x0206
# Define wm_mbuttondown 0x0207
# Define wm_mbuttonup 0x0208
# Define wm_mbuttondblclk 0x0209

Messages sent by non-customers
# Define wm_ncmousemove 0x00a0
# Define wm_nclbuttondown 0x00a1
# Define wm_nclbuttonup 0x00a2
# Define wm_nclbuttondblclk 0x00a3
# Define wm_ncrbuttondown 0x00a4
# Define wm_ncrbuttonup 0x00a5
# Define wm_ncrbuttondblclk 0x00a6
# Define wm_ncmbuttondown 0x00a7
# Define wm_ncmbuttonup 0x00a8
# Define wm_ncmbuttondblclk 0x00a9

 

# Define wm_nchittest 0x0084

 

Lparam indicates the cursor position, which is Y or X. For a message in a customer zone, it is the client zone coordinate. For a message in a non-customer zone, it is the screen coordinate.

Wparam indicates the mouse key, shift, and CTRL status for the client message.

The judgment is as follows:

Wparam & mk_lbutton

Wparam & mk_rbutton

Wparam & mk_mbutton

Wparam & mk_shift

Wparam & mk_control

These are useful when processing mousemove. For example, when moving, you can determine whether to press the button or shift or Ctrl.

For non-customer zone messages, it indicates the non-customer zone location to move or click.

 

3. Processing of mouse messages.

Key: wm_nchittest, hitting the Test message.

This message is superior to all other customer messages and non-customer mouse messages. Lparam represents X and Y screen coordinates. Wparam is useless.

The Window application sends the message to defwindowproc and generates all other mouse messages based on the mouse position.

For non-customer messages, the return value of defwindowproc is used as the parameter of wparam. This value can be added to any non-customer message with the following content:

Htclient client customer zone // if this is the case, the screen coordinates are converted to the left side of the customer zone, and then the customer zone message is generated.

Htnowhere is not in the window

The httransparent window is overwritten by another window.

Hrerror makes defwindowproc sound.

For example: Disable window mouse events:

Case wm_nchittest:

Return (lresult) htnowhere;

 

Iv. cursor functions:

Loadcursor

Setcursor

Showcursor

Getcursorpos

 

5. If a custom window does not contain cs_dblclks when it is defined, the window will not receive double-click events, but only two clicks are allowed.

 

6. Capture and release the mouse.

Setcapture (hwnd );

Releasecapture ();

After the mouse is captured, messages are transmitted to the hwnd window in the form of client messages no matter where the mouse is located to produce messages.

 

7. scroll wheel.

Message generated by the scroll wheel: wm_mousewheel

Wparam indicates whether the mouse key and shift \ CTRL are pressed

The high position of wparam indicates the direction of rotation. If it is positive and negative, it is equal to 120 or-120. 40 is a row, so scroll forward or backward three rows.

Lparam obtains the mouse position, relative to the upper left corner of the screen, rather than the customer area.

 

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.