views:

102

answers:

1

If I set a low level mouse hook, WH_MOUSE_LL,
when I click the [x] (Close) button the window delays ~500ms and then it disappears.

Do you know what causes the delay? And, is there a way to fix it?

(the window and the hook are created with direct calls to win32 api in C++)

+1  A: 

WH_MOUSE_LL is a different kind of hook from most other ones. It is implemented by calling the hook procedure directly rather than injecting a DLL. That requires a message loop to be actively pumping. The odds that there isn't one anymore after you close a window are high. Be sure to unhook in the WM_CLOSE message handler.

Hans Passant
@nobugz, I've tried your solution, and other combinations, but it didn't work. It's a normal (main) window with a message loop. With `WH_KEYBOARD_LL` I don't have that problem.
Nick D
I can't guess what the problem might be without seeing repro code. Post it to a file sharing service somewhere.
Hans Passant
ok, here is a demo: http://pastebin.com/m2fb3ca16
Nick D
No repro, it instantly closes. This suggests the problem is external.
Hans Passant
ok, thanks for helping. Did you try it on Windows XP or on newer version?
Nick D
Win7. Should work on XP as well.
Hans Passant