Hey, everybody!

I want to do something with a control that windows makes unnatural to say the least. I would like to have the control to react differently to single clicks and double clicks. Thing is if a double click occurs, I *don't* want it to do the single click action.

To clarify, double clicks are generated after an initial wm_lbuttondown/wm_lbuttonup. And I don't want the initial processing to be done if the double click is on it's way.

And yes, I know you can't predict the future.

Just wondering if people have some ideas. I was thinking about a flag to set in the first wm_lbuttondown, but then if the double click doesn't come, the flag is never checked.


Posted on 2002-05-31 11:53:16 by chorus

I never looked at this stuff (and I am not on my home pc right now, so I cannot look into my help files and MSDN does not load (Dunno why)) but couldn't you just start a timer AFTER one click occured and if the timer expires, treat it as a single click, but if you receive a second click during timer, it is a double click?

There are other ways, but this would be what I would try.

Best Luck

YaWNS aka Stefan K.
Posted on 2002-05-31 12:30:58 by YaWNS
I had the same thought as Yawns. A double click message always follows a single click message since even windows itself can't predict the future.

However, this means a single click action cannot start until after the delay of permissable double clicking. This is gonna make the control seem unresponsive (and might even cause a double click by the user) (under the HIT IT HARDER to make it work hypothesis).
Posted on 2002-05-31 19:09:58 by Ernie
Good idea guys. I honestly didn't think of a timer, but it seems reasonable. I think Ernie has got a point though.... I'm going to test it just to see how bad it is. After all, there is only a small time that a double click is allowed to occur in...

Quite honestly, I'm skeptical about this working out...

Thanks again
Posted on 2002-05-31 20:15:43 by chorus
Try something like this.

DidClick dd 0


CustMouseProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

; handle all mouse messages
.if uMsg == WM_TIMER
invoke KillTimer, hWnd, 1
mov DidClick, 0
; Do whatever you need on a single click here

.elseif uMsg == WM_LBUTTONDOWN
mov eax, DidClick
cmp eax, 1

; first click so set timer
mov DidClick, 1
invoke SetTimer, hWnd, 1, <somevalhere>, ADDR CustMouseProc

invoke KillTimer, hWnd, 1
mov DidClick, 0
; Do whatever you need on double click here

xor eax, eax
ret eax
.elseif uMsg == WM_LBUTTONDBLCLK
xor eax, eax
ret eax
.elseif uMsg == WM_LBUTTONUP
xor eax, eax
ret eax

invoke DefWindowProc, hWnd, uMsg, wParam, lParam
CustMouseProc endp

Where <somevalhere> is the length in milliseconds to wait for a double click. I did not test this but it looks sound.
Posted on 2002-06-01 00:38:53 by Graebel
Thanks for the code Graebal,
I ended up fiddling around with it a bit. Here's what I decided on:

In Window Proc:

je @@LButtonDown
je @@LButtonDblClk
@@LButtonDown: mov DidClick,-1
invoke SetTimer,hWin,1,200,addr MouseFunc
xor eax,eax
@@LButtonDblClk: xor DidClick,-1
jnz @F
invoke OpenFileProc,NULL
@@: ret

MouseFunc PROC hWin,uMsg,idEvent,dwTime:DWORD
xor DidClick,-1
jnz @F
invoke ShowWindow,hWin,SW_SHOWMAXIMIZED
@@: invoke KillTimer,hWin,1
MouseFunc ENDP

Went with a timer of about 200 milliseconds, and it seems okay. All it does is Maximize the window on a single click and call an open file procedure on a double click. Those weren't really the specific functions I had in mind, but I just wanted something that worked. Note that you have to use xor DidClick,-1 instead of not DidClick because the not instruction doesn't update the flags.

What it'll probably end up doing is handling the context menu for the right mouse button. A double click will execute the default command without showing the menu, while a single click will pop up the menu.

Thanks everybody

Posted on 2002-06-01 11:28:32 by chorus