Modify ↓
#2910 closed Bug (Fixed)
Example for _WinAPI_RegisterShellHookWindow() not working
| Reported by: | Owned by: | guinness | |
|---|---|---|---|
| Milestone: | 3.3.13.20 | Component: | Documentation |
| Version: | 3.3.12.0 | Severity: | None |
| Keywords: | Cc: |
Description
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.
Attachments (0)
Change History (3)
comment:2 by , on Sep 29, 2014 at 7:14:31 AM
| Component: | AutoIt → Documentation |
|---|
comment:3 by , on Oct 10, 2014 at 7:39:54 PM
| Milestone: | → 3.3.13.20 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [11118] in version: 3.3.13.20
Note:
See TracTickets
for help on using tickets.

Sorry I clicked the wrong component. Needs to be "Documentation" instead of AutoIt.