Modify

Opened 11 years ago

Closed 11 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 by Synix <cross.fire@…>, 11 years ago

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

comment:2 by jchd18, 11 years ago

Component: AutoItDocumentation

comment:3 by guinness, 11 years ago

Milestone: 3.3.13.20
Owner: set to guinness
Resolution: Fixed
Status: newclosed

Fixed by revision [11118] in version: 3.3.13.20

Modify Ticket

Action
as closed The owner will remain guinness.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.