How to distinguish between double-click and double-click

Source: Internet
Author: User

How to distinguish between double-click and double-click

Http://lbsloveldm.blog.hexun.com/12212875_d.html

On the Windows platform, pressing, releasing, and clicking the left mouse button quickly will generate messages such as wm_lbuttondown, wm_lbuttonup, and wm_lbuttondblclk, is it two independent clicks or one double-click? Recently, I used spy ++ and msdn to solve this problem. Summary:
Windows makes this distinction based on two conditions:
(1) double-click Interval
This is easy to think. More accurately,

Two clicks generate four mouse clicks. If the interval between the third message (the second press) and the second message (the wm_lbuttonup triggered by the first bounce) is shorter than the specified value, the third message is processed as the wm_lbuttondblclk message. The fourth message is the same as the previous one, and the wm_lbuttonup message.

The specified time interval is 0.5 seconds by default on Windows XP SP2, and may be the same for other operating systems. Use: getdoubleclicktime to obtain this value.
This value can be set. There are two ways to set this value: setdoubleclicktime call, or use spi_setdoubleclicktime as the first parameter to call: systemparametersinfo. The setting result also works for other applications in the system.
(2) space distance between two mouse clicks
During the first click, Windows detects a rectangular area centered on the click. If the second click is not placed in this area, the third message is not counted as the wm_lbuttondblclk message.
The default size of this rectangular area. The default value is 4pt × 4pt on Windows XP SP2. You can call it with sm_cxdoubleclk or sm_cydoubleclk as the parameter: getsystemmetrics.
This value can also be set. The setting method is to use spi_setdoubleclkwidth or spi_setdoubleclkheight as the first parameter to call: systemparametersinfo. The setting result also works for other applications in the system.

Therefore, two consecutive clicks and the left mouse button is displayed:

If the two conditions are not met, the message is:
Wm_lbuttondown
Wm_lbuttonup
Wm_lbuttondown
Wm_lbuttonup

If the preceding two conditions are met, the message is:
Wm_lbuttondown
Wm_lbuttonup
Wm_lbuttondblclk
Wm_lbuttonup

The above conclusions also imply two points:
(1) Whether counted as two consecutive clicks or one double-click, messages 1, 2, and 4 are not affected. Before receiving a double-click message, the application always receives a wm_lbuttondown message and a wm_lbuttonup message, followed by a wm_lbuttonup message. The application should properly process various messages;
(2) The second message and the third message are critical and must be continuously sent to the same window before being processed. A common error in development is as follows: when processing the first message wm_lbuttondown or wm_lbuttonup, capture the subsequent mouse messages through setcapture and forward them to another window. As a result, the original window cannot be identified by double-clicking, this double-click may be expected.

From: http://blog.163.com/guochunhui3024@126/blog/static/25589885201152182524176/

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.