Reputation: 3357
i am using OnLButtonUp and OnLButtonDblClk in my application but whenever i double click OnLButtonDblClk and OnLButtonUp both called but i wanted only OnLButtonDblClk to be called not OnLButtonUp . How to do this?
Upvotes: 0
Views: 2887
Reputation: 21
OnLButtonUp(UINT nFlags, CPoint point)
{
Sleep(::GetDoubleClickTime());
MSG msg;
if( ::PeekMessage(&msg, NULL, WM_LBUTTONDBLCLK, WM_LBUTTONDBLCLK, PM_NOREMOVE) )
return; // LEFT CONTROL TO DBL CLICK ;-)
// NORMAL OnLButtonUp
}
Upvotes: 2
Reputation: 3466
The problem is that whenever the user double clicks there are four messages sent:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_LBUTTONUP
This only happens if the user clicks the second time within the "double click time" (use ::GetDoubleClickTime()
to get it).
So what you can do is set a timer (with a timeout value equal to the double click time) when the user first clicks and if the second click comes before the timer goes off, you have a double click and you can disregard the button up message.
If the timer goes off, you call your button-up handler.
This technique has the drawback that it delays a bit the response to "Button Up" or single click, depending how you do it, but there's no easy way to discard just the Button Up messages when there's a double click.
EDIT: If you just want to discard the second WM_LBUTTONUP, you can use a flag. You set it when you receive WM_LBUTTONDBLCLK. Then in the handler for WM_LBUTTONUP you do nothing if it's set (and then you clear it, of course).
Upvotes: 3