JustinNL wrote: ↑14 Feb 2022, 07:00
I tried your hotkey file and I could clearly follow the message, but the window (it is some sort of warning message) does not appear to trigger any HSHELL event.
...
Would you have any final suggestion on how to use an Event Hook if possible? If not I'll stick to the SetTimer approach.
An Event Hook has to hook into event messages for a certain process.
He is some monitoring code that might help.
Code: Select all
Gui, +AlwaysOnTop
Gui, Add, ListView, h200 w870, Count|WinTitle|ahk_class|hWinEventHook|event|hwnd|idObject|idChild|dwEventThread|dwmsEventTime
for Col, Width in [50, 150, 100, 100, 50, 80, 80, 50, 100, 100]
LV_ModifyCol(Col, Width)
Gui, Show, x10 y10
OnExit, UnHook
; ExcelPID is used for the idProcess parameter when calling SetWinEventHook
Process, Exist, EXCEL.EXE
if ErrorLevel
ExcelPID := ErrorLevel
/* HWINEVENTHOOK WINAPI SetWinEventHook
* - http://msdn.microsoft.com/en-us/library/windows/desktop/dd373640%28v=vs.85%29.aspx
* Event Constants
* - http://msdn.microsoft.com/en-us/library/windows/desktop/dd318066%28v=vs.85%29.aspx
*/
;EVENT_OBJECT_CREATE := 0x8000
;EVENT_OBJECT_FOCUS := 0x8005
;EVENT_OBJECT_LOCATIONCHANGE := 0x800B
EVENT_SYSTEM_MOVESIZEEND := 0x000B
EVENT_SYSTEM_MOVESIZESTART := 0x000A
WINEVENT_OUTOFCONTEXT := 0x0
WINEVENT_SKIPOWNPROCESS := 0x2
Hook := DllCall("SetWinEventHook"
, "UInt", EVENT_SYSTEM_MOVESIZESTART ;_In_ UINT eventMin
, "UInt", EVENT_SYSTEM_MOVESIZEEND ;_In_ UINT eventMax
, "Ptr" , 0x0 ;_In_ HMODULE hmodWinEventProc
, "Ptr" , RegisterCallback("WinEventProc") ;_In_ WINEVENTPROC lpfnWinEventProc
, "UInt", ExcelPID ;_In_ DWORD idProcess
, "UInt", 0x0 ;_In_ DWORD idThread
, "UInt", WINEVENT_OUTOFCONTEXT|WINEVENT_SKIPOWNPROCESS) ;_In_ UINT dwflags
return
/* WinEventProc callback function
* - http://msdn.microsoft.com/en-us/library/windows/desktop/dd373885%28v=vs.85%29.aspx
*/
WinEventProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime) {
static Count := 0
WinGetTitle, WinTitle, ahk_id %hwnd%
WinGetClass, WinClass, ahk_id %hwnd%
LV_Insert(1, "", ++Count, WinTitle, WinClass, hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime)
return
}
UnHook:
DllCall("UnhookWinEvent", "Ptr",Hook)
GuiEscape:
GuiClose:
ExitApp
This code is setup to monitor events from Excel. Excel has to be running before you start this code. Then this code gets a hook into the Excel.exe process and watches for event messages.
You can try this code out with Excel to see what it does when you do things like move, resize, create children windows, etc. of Excel.
Then you will need to change this
Process, Exist, EXCEL.EXE to the process of your program and attempt to monitor it for event messages. If you find one that reliably comes up when the window you want opens, then you can work on creating an Event Hook for it. There are lots of examples of Event Hooks on the forums or you can just use the WinHook class that does all the hard work for you once you know the event number to watch for.
FG