code not running after I register a shell hook

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dirtyacc
Posts: 10
Joined: 16 Oct 2019, 01:19

code not running after I register a shell hook

16 Oct 2019, 01:24

Code: Select all

Gui +LastFound
hWnd:=WinExist()
DllCall("RegisterShellHookWindow", UInt,hWnd)
MsgNum:=DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "SwitchMessage")
HSHELL_WINDOWCREATED:=1
Return
msgbox, TEST
I used the above codes to hook the shell message, but I found the many code after that will stop running, like the "msgbox, TEST" above. The hook itself work as expected, are there anything I did it wrong?
gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: code not running after I register a shell hook

16 Oct 2019, 01:52

I don't think it has to do with the hook, but msgbox, TEST is unreachable code because of the return above it... just remove the return.
dirtyacc
Posts: 10
Joined: 16 Oct 2019, 01:19

Re: code not running after I register a shell hook

16 Oct 2019, 05:28

gregster wrote:
16 Oct 2019, 01:52
I don't think it has to do with the hook, but msgbox, TEST is unreachable code because of the return above it... just remove the return.
gosh. you're right. But I still got problem:

Code: Select all

Gui +LastFound
hWnd:=WinExist()
DllCall("RegisterShellHookWindow", UInt,hWnd)
MsgNum:=DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "SwitchMessage")
HSHELL_WINDOWCREATED:=1

SwitchMessage( wParam,lParam ) 
{
	If ( wParam != 1 )	
	{
		If WinActive("ahk_exe explorer.exe")
			{
				MsgBox, explorer detected!
			}
	}
}

ReloadTimer := % 1000*5
;reload timer
Gosub,AutoReloadInit
AutoReloadInit:
	SetTimer, SelfReload, % ReloadTimer
return

SelfReload:
	MsgBox, TEST
	reload
return
Above code work, if I put the settimer after the shell hook, both the timer and the shell hook work as expected.

But if I put hte setTimer in front of the shell hook, the hook won't work, would you please tell me why?

Code: Select all

ReloadTimer := % 1000*5
;reload timer
Gosub,AutoReloadInit
AutoReloadInit:
	SetTimer, SelfReload, % ReloadTimer
return

SelfReload:
	MsgBox, TEST
	reload
return


Gui +LastFound
hWnd:=WinExist()
DllCall("RegisterShellHookWindow", UInt,hWnd)
MsgNum:=DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "SwitchMessage")
HSHELL_WINDOWCREATED:=1

SwitchMessage( wParam,lParam ) 
{
	If ( wParam != 1 )	
	{
		If WinActive("ahk_exe explorer.exe")
			{
				MsgBox, explorer detected!
			}
	}
}

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: code not running after I register a shell hook

16 Oct 2019, 18:48

I believe, your last question was already answered by tmplinshi in the parallel chinese topic: https://www.autohotkey.com/boards/viewtopic.php?f=27&t=68921&p=296776#p296776

To cut it short: this time, you made another part of your code unreachable (the part with the hook) by placing it below a return:

Code: Select all

; [...]
return			; this return makes the following code unreachable


Gui +LastFound		; here is no label to jump to - this code gets never executed
hWnd:=WinExist()
DllCall("RegisterShellHookWindow", UInt,hWnd)
MsgNum:=DllCall("RegisterWindowMessage", Str,"SHELLHOOK")
OnMessage(MsgNum, "SwitchMessage")
HSHELL_WINDOWCREATED:=1
;[...]
tmplinshi showed a way to change this code so that it will run as intended: https://www.autohotkey.com/boards/viewtopic.php?f=27&t=68921&p=296776#p296762

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, roysubs and 171 guests