-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewWindowNotifier.ahk
73 lines (65 loc) · 1.57 KB
/
newWindowNotifier.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class WindowCreateAndCloseWatcherClass
{
static shellHookSetup := false
openCallbacks := []
closeCallbacks := []
__new()
{
return this.__setupShellhook()
}
registerOpenCallback(callback)
{
this.openCallbacks.Insert(callback)
return this
}
registerCloseCallback(callback)
{
this.closeCallbacks.Insert(callback)
return this
}
__setupShellhook()
{
if(! this.shellHookSetup)
{
this.shellHookSetup := true
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, func("WindowCreateAndCloseWatcherClass.newWindowCallback").bind(this))
}
return this
}
notifyOpenListeners(ahkWindowId)
{
for index, callback in this.openCallbacks
{
callback.call(new WindowObjectClass("ahk_id " ahkWindowId))
}
return this
}
;todo figure out what paramater is passed to this function and if it is useful
notifyCloseListeners(notSureWhatThisIs)
{
for index, callback in this.closeCallbacks
{
callback.call(notSureWhatThisIs)
}
return this
}
newWindowCallback(wParam, lParam)
{
HSHELL_WINDOWDESTROYED := 2
HSHELL_WINDOWCREATED := 1
if (wParam == HSHELL_WINDOWCREATED)
{
funcObj := func("WindowCreateAndCloseWatcherClass.notifyOpenListeners").bind(this, ahkWindowId := lParam)
setTimer % funcObj, -1
} else if (wParam == HSHELL_WINDOWDESTROYED)
{
funcObj := func("WindowCreateAndCloseWatcherClass.notifyCloseListeners").bind(this, ahkWindowId := lParam)
setTimer % funcObj, -1
}
return this
}
}