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.