I'm having problems exiting and reloading a script that uses WinEventHook Messages from here:
https://autohotkey.com/board/topic/3266 ... -messages/
The script works well for its purpose (described below) but most of the time it crashes AutoHotkey ANSI 32 bit 1.1.23.01 (on Windows 7 64 bit) when I reload the script (by either pressing F8 or by double-clicking on the .ahk file if it's already running), and crashes randomly when I exit or Winclose the script. Can anyone offer any help as to why it would crash and also any potential fix? Could it be because of the version of AHK used (ANSI 32 bit), which I need to use for compatibility with other scripts?
The script is used with PowerPoint. If you have a slideshow running and add annotations with the pen pointer, when you exit the slideshow a window pops up asking if you want to Keep or Discard the annotations. This script detects this popup window and then will show a tooltip corresponding to the option selected (Kept! or Discarded!). As I mentioned, it works well for this purpose, but crashes on exit/reload.
Thanks in advance for any help you may be able to provide. If there is no easy fix using WinEventHook Messages, I'm also open to any other idea to capture the popup window and the selected option!
Cheers!
Code: Select all
;Shell hook to capture if ink annotations are kept or discarded
; https://autohotkey.com/board/topic/32662-tool-wineventhook-messages/
#SingleInstance, force
#NoEnv
#Persistent
SetBatchLines -1
HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x8, 0x8, 0, HookProcAdr, 0, 0, 0 )
OnExit, ExitSub
Return
ExitSub:
UnhookWinEvent()
ExitApp
Return
F8::
UnhookWinEvent()
sleep, 1000
Reload
Return
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
Global
if Event ; EVENT_SYSTEM_CAPTURESTART = 0x8
{
IfWinActive, ahk_exe POWERPNT.EXE
{
WinGetClass, class, ahk_id %hWnd%
WinGetTitle, Title, ahk_id %hWnd%
If ((Class = "Button") and (Title = "&Discard"))
Tooltip, Discarded!
If ((Class = "Button") and (Title = "&Keep"))
Tooltip, Kept!
;Tooltip, 1_%Class%`n2_%hwnd%`n3_%idObject%`n4_%idChild%`n5_%dwEventThread%`n6_%dwmsEventTime%`n7_%Title%
}
}
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook"
, Uint,eventMin
, Uint,eventMax
, Uint,hmodWinEventProc
, Uint,lpfnWinEventProc
, Uint,idProcess
, Uint,idThread
, Uint,dwFlags)
}
UnhookWinEvent()
{
Global
DllCall( "UnhookWinEvent", Uint,hWinEventHook )
DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}