How to distinguish between "mouse click" and "double-click mouse" in Win32"

Source: Internet
Author: User

When writing a Win32 program today, I encountered a problem, that is, when I responded to the double-click event, I first responded to the event. So I made up my mind to solve this problem. Later, I realized that double-clicking is composed of two mouse clicks, But windows judges the time when the two mouse clicks, if the two mouse clicks within ms, double-click event. If it exceeds 200 ms, it indicates two single-host events of the mouse. So how does one not respond to the mouse click event while responding to double-clicking the mouse? That is, to filter out mouse click events. There are two methods to achieve this.

 

(1) Add the following filter conditions to the Message response wm_lbuttondown.

DWORD st;

DWORD et;

MSG;

St = gettickcount ();

While (1)

{

If (: peekmessage (& MSG, null, 0, 0, pm_remove ))

{

: Translatemessage (& MSG );

: Disatchmessage (& MSG );}

If (wm_lbuttondblclk = MSG. Message)

{

Return defwindowproc (hwnd, message, wparam, lparam );

}

ET = gettickcount (); If (ET-ST> 200) break ;}

In this way, when you respond to a message that is double-clicked, the response is not responded.

 

(2) Use sleep (getdoubleclicktime () to add

Static bool flag = false;

Sleep (getdoubleclicktime ());

If (FLAG) {return 0 ;}

Flag = false;

Add the following content to wm_lbuttondblclk:

Flag = true;

The purpose is: When you double-click the mouse, the message response wm_lbuttondown is first entered,

After sleep (getdoubleclicktime,

The message response enters the wm_lbuttondblclk. At this time, the flag becomes true,

After sleep ends, the Message continues to return to lbuttondown,

In this case, if the flag value is true, return. I hope this article will help people who need it solve the problem.

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.