Opened 10 years ago
Closed 10 years ago
#2910 closed Bug (Fixed)
Example for _WinAPI_RegisterShellHookWindow() not working
Reported by: | Synix <cross.fire@…> | 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:1 Changed 10 years ago by Synix <cross.fire@…>
comment:2 Changed 10 years ago by jchd18
- Component changed from AutoIt to Documentation
comment:3 Changed 10 years ago by guinness
- Milestone set to 3.3.13.20
- Owner set to guinness
- Resolution set to Fixed
- Status changed from new to closed
Fixed by revision [11118] in version: 3.3.13.20
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Sorry I clicked the wrong component. Needs to be "Documentation" instead of AutoIt.