Is there any "Shell Hook" Alternative?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User
Posts: 407
Joined: 26 Jun 2017, 08:12

Is there any "Shell Hook" Alternative?

25 Dec 2018, 13:22

"Shell Hook" has some absurdities that I really don't want to use it!

For example, "HSHELL_WINDOWDESTROYED" is triggered when windows are "destroyed" but it is also triggered when windows are "Hidden"! (Hehe, these so called developers really make me Lol times to times!)

Anyway, the code below demonstrates what I mentioned above:

Code: Select all

	;https://autohotkey.com/board/topic/80644-how-to-hook-on-to-shell-to-receive-its-messages/#entry116488


Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )

loop, 3
{
gui, % a_index ":default"

gui, +HwndTempGuiId

gui, add, button, ghide, Hide gui

xPos := a_index = 1 ? a_screenwidth/2 - 320 : a_index = 2 ? a_screenwidth/2 - 100 : a_screenwidth/2 + 120

gui, show,  % "x" xpos " w200 h200",  % TempGuiId 
}

msgbox, Press Ok to Exit!

ExitApp


hide:		;___________ hide gui __________

gui, hide

return


ShellMessage( wParam,lParam )	;______________ Shell Message ______________
{

	;if "wParam = 2", a window was hidden or destroyed (HSHELL_WINDOWDESTROYED)

if (wParam = 2)
msgbox, % "Window " lParam " / " Format("{1:#x}", lParam) " was destroyed!"

}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Is there any "Shell Hook" Alternative?

25 Dec 2018, 14:50

u can use DetectHiddenWindows and check if it was hidden or destroyed

Code: Select all

;https://autohotkey.com/board/topic/80644-how-to-hook-on-to-shell-to-receive-its-messages/#entry116488
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt, hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
DetectHiddenWindows On

loop, 3
{
	gui, % a_index ":default"
	gui, +HwndTempGuiId
	gui, add, button, ghide, Hide gui
	xPos := a_index = 1 ? a_screenwidth/2 - 320 : a_index = 2 ? a_screenwidth/2 - 100 : a_screenwidth/2 + 120
	gui, show,  % "x" xpos " w200 h200",  % TempGuiId 
}

msgbox, Press Ok to Exit!
ExitApp

hide:		;___________ hide gui __________
gui, hide
return

GuiClose:
	Gui Destroy
Return

2GuiClose:
	Gui 2: Destroy
Return

3GuiClose:
	Gui 3: Destroy
Return

ShellMessage( wParam,lParam )	;______________ Shell Message ______________
{
	;if "wParam = 2", a window was hidden or destroyed (HSHELL_WINDOWDESTROYED)
	if (wParam = 2)
	{
		if WinExist("ahk_id " lParam)
			msgbox, % "Window " lParam " / " Format("{1:#x}", lParam) " was hidden!"
		else
			msgbox, % "Window " lParam " / " Format("{1:#x}", lParam) " was destroyed!"
	}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 221 guests