﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2910	Example for _WinAPI_RegisterShellHookWindow() not working	Synix <cross.fire@…>	guinness	"The default example script from the help file doesn't work on my windows 7 x64 system:
{{{
#include <APISysConstants.au3>
#include <WinAPISys.au3>

Opt('TrayAutoPause', 0)

OnAutoItExitRegister('OnAutoItExit')

Global $g_hForm = GUICreate('')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), 'WM_SHELLHOOK')
_WinAPI_RegisterShellHookWindow($g_hForm)

While 1
    Sleep(1000)
WEnd

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg

    Switch $hWnd
        Case $g_hForm
            Switch $wParam
                Case $HSHELL_WINDOWACTIVATED
                    Local $sTitle = WinGetTitle($lParam)

                    If IsString($sTitle) Then
                        ConsoleWrite('Activated: ' & $sTitle & @CRLF)
                    EndIf
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Func OnAutoItExit()
    _WinAPI_DeregisterShellHookWindow($g_hForm)
EndFunc   ;==>OnAutoItExit
}}}

In the following code, I fixed that and removed the unneccessary disabling of TrayAutoPause. Also the GUI is now shown and closable, so searching for the tray icon to exit isn't needed anymore:
{{{
#include <GUIConstantsEx.au3>
#include <WinAPISys.au3>

OnAutoItExitRegister('OnAutoItExit')
Global $hGUI = GUICreate('')
Global $idButton = GUICtrlCreateButton(""Activate hidden AutoIt window"", 10, 10)
Global $iWndMsgID = _WinAPI_RegisterWindowMessage('SHELLHOOK')
GUIRegisterMsg($iWndMsgID, 'WM_SHELLHOOK')
ConsoleWrite(""Registered Shell hook window: "" & (_WinAPI_RegisterShellHookWindow($hGUI) = 1) & @CRLF)
GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			Exit
		Case $idButton
			_SendMessage($hGUI, $iWndMsgID, $HSHELL_WINDOWACTIVATED, WinGetHandle(AutoItWinGetTitle()))
	EndSwitch
WEnd

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
	#forceref $iMsg

	Switch $hWnd
		Case $hGUI
			If BitAND($wParam, $HSHELL_WINDOWACTIVATED) = $HSHELL_WINDOWACTIVATED Then
				Local $sTitle = WinGetTitle($lParam)
				If IsString($sTitle) Then
					ConsoleWrite('Activated: ' & $sTitle & @CRLF)
				EndIf
			EndIf
	EndSwitch
EndFunc   ;==>WM_SHELLHOOK

Func OnAutoItExit()
	ConsoleWrite(""Unregistered Shell hook window: "" & (_WinAPI_DeregisterShellHookWindow($hGUI) = 1) & @CRLF)
EndFunc   ;==>OnAutoItExit
}}}
The _SendMessage button was only implemented to make the GUI look less useless. Would liked to have the hidden AutoIt window as the actual shell hook window instead, but it looks like thats technically impossible since it has its own special window class."	Bug	closed	3.3.13.20	Documentation	3.3.12.0	None	Fixed		
