Sign in to follow this  
Followers 0
4ggr35510n

MouseProc SetWindowsHookEx failure...

2 posts in this topic

#1 ·  Posted (edited)

Greetings!

I have some serious issues with registering MouseProc with SetWindowsHookEx function...

As long as mouse stays inside the GUI - console returns messages etc. - properly!

But as soon as mouse leaves GUI window - everything stops, no more messages...

Here's the code:

OnAutoItExitRegister('OnAutoItExit')


$hKey_Proc = DllCallbackRegister("MouseProc", "int", "int;ptr;ptr")

$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)

$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", 7, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)

; unlogical!
GUICreate('Test')
GUISetState()

Do
Until GuiGetMsg() = -3
Exit


Func MouseProc($nCode, $wParam, $lParam)
    ConsoleWrite($nCode )

    Switch $wParam
        Case 0x0201
            ConsoleWrite(@CRLF & 'LEFT DOWN' & @CRLF)
        Case 0x0202
            ConsoleWrite(@CRLF & 'LEFT UP' & @CRLF)
        Case 0x0206
            ConsoleWrite(@CRLF & 'RIGHT DOUBLE DOWN' & @CRLF)
        Case 0x020A
            ConsoleWrite(@CRLF & 'WHEEL' & @CRLF)
    EndSwitch

EndFunc

Func OnAutoItExit()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
    $hM_Hook[0] = 0
    DllCallbackFree($hKey_Proc)
    $hKey_Proc = 0
EndFunc   ;==>OnAutoItExit

What's wrong? How should it look like to work properly?

Basically, I'd like to create non-Low Level MouseHook for receiving mouse msg just from one window.

Non-Low Levelr = CPU saving purpose. (same code with $WH_LL_MOUSE insetad of $WH_MOUSE [int 7 stands for it] works perfectly... why? :graduated:)

BR, I hope for your help :]

4gr

Edited by 4ggr35510n

Share this post


Link to post
Share on other sites



You may want to look at the following:


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0