forked from 7plus/7plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageHooks.ahk
273 lines (263 loc) · 10.6 KB
/
MessageHooks.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
; see http://msdn.microsoft.com/en-us/library/dd318066(VS.85).aspxs
HookProc(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime ){
global ResizeWindow, SlideWindows, WindowList
ListLines, Off
hwnd += 0
;On dialog popup, check if its an explorer confirmation dialog
if(event = 0x00008002) ;EVENT_OBJECT_SHOW
{
if(IsObject(Settings) && Settings.Explorer.AutoCheckApplyToAllFiles && WinVer >= WIN_Vista)
FixExplorerConfirmationDialogs()
return
}
if idObject or idChild ;Doesn't each much time, skip for profiling
return
WinGet, style, Style, ahk_id %hwnd%
if (style & 0x40000000) ;return if hwnd is child window, for some reason idChild may be 0 for some children ?!?! ( I hate ms )
return
if(event = 0x0016) ;EVENT_SYSTEM_MINIMIZEEND
{
Trigger := new CWindowStateChangeTrigger()
Trigger.Window := hwnd
Trigger.Event := "Window minimized"
EventSystem.OnTrigger(Trigger)
}
else if(event = 0x8001 && IsObject(Settings) && Settings.Explorer.Tabs.UseTabs) ;EVENT_OBJECT_DESTROY
{
; DecToHex(hwnd)
; if(TabContainerList.ContainsHWND(hwnd))
}
else if(event = 0x800B) ;EVENT_OBJECT_LOCATIONCHANGE
{
WinGet, state, minmax, ahk_id %hwnd%
if(state = 1)
{
Trigger := new CWindowStateChangeTrigger()
Trigger.Window := hwnd
Trigger.Event := "Window maximized"
EventSystem.OnTrigger(Trigger)
}
if(InStr("CabinetWClass,ExploreWClass", WinGetClass("ahk_id " hwnd)))
ExplorerMoved(hwnd)
if(IsObject(SlideWindows))
SlideWindows.CheckResizeReleaseCondition(hwnd)
if(state != -1)
{
WindowList.MovedWindow := hwnd
SetTimer, UpdateWindowPosition, -1000
}
}
else if(event = 0x000A && Settings.Windows.ShowResizeTooltip)
{
ResizeWindow := hwnd
SetTimer, ResizeWindowTooltip, 50
SlideWindows.CheckResizeReleaseCondition(hwnd)
}
else if(event = 0x000B)
{
ShowTip({Min : 4, Max : 7}, 0.1)
if(Settings.Windows.ShowResizeTooltip)
{
ResizeWindow := ""
SetTimer, ResizeWindowTooltip, Off
ResizeWindowTooltip(true)
Tooltip
}
}
ListLines, On
}
ResizeWindowTooltip:
ResizeWindowTooltip()
return
ResizeWindowTooltip(reset = false)
{
global ResizeWindow
static w,h
if(reset)
{
w:=0
h:=0
return
}
WinGetPos, , , wn, hn, ahk_id %ResizeWindow%
if(w && h && (w != wn || h != hn))
Tooltip %w%/%h%
w := wn
h := hn
}
;See http://msdn.microsoft.com/en-us/library/ms644991(VS.85).aspx
ShellMessage( wParam, lParam, Msg)
{
WasCritical := A_IsCritical
Critical
ListLines, Off
global BlinkingWindows, WindowList, Accessor, RecentCreateCloseEvents, ToolWindows, ExplorerWindows, LastWindow, LastWindowClass, SlideWindows, CurrentWindow, PreviousWindow, ExplorerHistory
Trigger := new COnMessageTrigger()
Trigger.Message := wParam
Trigger.lParam := lParam
Trigger.Msg := Msg
EventSystem.OnTrigger(Trigger)
if(wParam = 1 || wParam = 2) ;Window Created/Closed
{
lParam += 0
;Keep a list of recently received create/close messages, because they can be sent multiple times and we only want one.
if(!IsObject(RecentCreateCloseEvents))
RecentCreateCloseEvents := Array()
SetTimer, ClearRecentCreateCloseEvents, -300
if(!RecentCreateCloseEvents.HasKey(lParam))
{
RecentCreateCloseEvents[lParam] := 1
Trigger := wParam = 1 ? new CWindowCreatedTrigger() : new CWindowClosedTrigger()
class := wParam = 1 ? WinGetClass("ahk_Id " lParam) : (IsObject(WindowList) && IsObject(WindowList[lParam]) ? WindowList[lParam].class : "INVALID WINDOW CLASS")
Trigger.Window := lParam
EventSystem.OnTrigger(Trigger)
;Keep a list of windows and their required info stored. This allows to identify windows which were closed recently.
WinGet, hwnds, list,,, Program Manager
Loop, %hwnds%
{
hwnd := hwnds%A_Index%+0
WinGetTitle, title, ahk_id %hwnd%
if(IsObject(WindowList[hwnd]))
WindowList[hwnd].title := title
else
{
WinGetClass, class, ahk_id %hwnd%
WinGet, exe, ProcessName, ahk_id %hwnd%
WinGet, Path, ProcessPath, ahk_id %hwnd%
WindowList[hwnd] := Object("class", class, "title", title, "Executable", exe, "Path", Path)
}
}
}
if(wParam = 2)
{
if(IsObject(WindowList[lParam]) && InStr("CabinetWClass,ExploreWClass", WindowList[lParam].class))
GoSub WaitForClose
else ;Code below is also executed in WaitForClose for separate Explorer handling (why can't explorer send close messages properly like a normal window??)
{
if(IsObject(ToolWindows))
{
Loop % ToolWindows.MaxIndex()
{
if(ToolWindows[A_Index].hParent = lParam && ToolWindows[A_Index].AutoClose)
{
WinClose % "ahk_id " ToolWindows[A_Index].hGui
ToolWindows.Remove(A_Index)
break
}
}
}
SlideWindows.WindowClosed(lParam)
}
}
if(wParam = 1)
{
if(IsObject(SlideWindows))
SlideWindows.WindowCreated(lParam)
AutoCloseWindowsUpdate(lParam)
;~ SlideWindows.CreatedWindow := lParam
;~ SetTimer, SlideWindows_WindowCreated, -100
} ; SlideWindows.WindowCreated(lParam)
}
;Blinking windows detection, add new blinking windows
else if(wParam = 32774)
{
lParam += 0
if(!BlinkingWindows.indexOf(lParam))
{
BlinkingWindows.Insert(lParam)
ShowTip(12)
}
}
;Window Activation
else if(wParam = 4 || wParam = 32772) ;HSHELL_WINDOWACTIVATED||HSHELL_RUDEAPPACTIVATED
{
ShowTip(13, 0.05)
if(IsAltTabWindow(lParam))
{
PreviousWindow := CurrentWindow
CurrentWindow := lParam
}
lParam += 0
Trigger := new CWindowActivatedTrigger()
EventSystem.OnTrigger(Trigger)
;Blinking windows detection, remove activated windows
if(x := BlinkingWindows.indexOf(lParam))
BlinkingWindows.Delete(x)
if(IsObject(CAccessor.Instance.GUI) && CAccessor.Instance.Settings.CloseWhenDeactivated && WinExist("A") != CAccessor.Instance.GUI.hwnd)
CAccessor.Instance.Close()
;If we change from another program to explorer/desktop/dialog
if((IsExplorer := WinActive("ahk_group ExplorerGroup"))||WinActive("ahk_group DesktopGroup")||IsDialog())
{
if(!WinActive("ahk_group DesktopGroup")) ;By doing this, recall explorer path works also when double clicking desktop to launch explorer
Settings.Explorer.CurrentPath := Navigation.GetPath()
;Paste text/image as file file creation
CreateFileFromClipboard()
if((IsExplorer && ExplorerWindows.GetItemWithValue("hwnd", IsExplorer).Path != Settings.Explorer.CurrentPath) || !IsExplorer)
{
Entry := RichObject()
Name := Entry.Path := Settings.Explorer.CurrentPath
SplitPath, Name, Name
Entry.Name := IsExplorer ? Navigation.GetDisplayName(lParam) : Name
Entry.Usage := 0
Entry := ExplorerHistory.Push(Entry) ;This can return a different entry that already exists in the list!
Entry.Usage++
}
}
if(LastWindowClass && InStr("CabinetWClass,ExploreWClass", LastWindowClass) && !ExplorerWindows.TabContainerList.TabCreationInProgress && !ExplorerWindows.TabContainerList.TabActivationInProgress)
ExplorerDeactivated(LastWindow)
LastWindow := lParam
LastWindowClass := WinGetClass("ahk_id " lParam)
if(InStr("CabinetWClass,ExploreWClass", LastWindowClass) && LastWindowClass && !ExplorerWindows.TabContainerList.TabCreationInProgress && !ExplorerWindows.TabContainerList.TabActivationInProgress)
ExplorerActivated(LastWindow)
if(IsObject(SlideWindows))
SlideWindows.WindowActivated()
}
;Redraw is fired on Explorer path change
else if(wParam = 6)
{
lParam += 0
;Detect changed path
if(InStr("CabinetWClass,ExploreWClass", WinGetClass("ahk_id " lParam)))
{
ExplorerPathChanged(ExplorerWindows.GetItemWithValue("hwnd", lParam))
; newpath := Navigation.GetPath()
; if(newpath && newpath != Settings.Explorer.CurrentPath)
; {
; Debug("Explorer path changed from " ExplorerPath " to " newpath)
; ExplorerPathChanged(Settings.Explorer.CurrentPath, newpath)
; Settings.Explorer.PreviousPath := Settings.Explorer.CurrentPath
; Settings.Explorer.CurrentPath := newpath
; Trigger := new CExplorerPathChangedTrigger()
; EventSystem.OnTrigger(Trigger)
; if(Settings.Explorer.Tabs.UseTabs && !SuppressTabEvents && hwnd:=WinActive("ahk_group ExplorerGroup"))
; UpdateTabs()
; }
}
}
ListLines, On
if(!WasCritical)
Critical, Off
}
;Timer for clearing the list of recently received create/close events
ClearRecentCreateCloseEvents:
RecentCreateCloseEvents := Array()
return
UpdateWindowPosition:
UpdateWindowPosition()
return
UpdateWindowPosition()
{
global WindowList
WinGetPos, x, y, w, h, % "ahk_id " WindowList.MovedWindow
if(!IsObject(WindowList[WindowList.MovedWindow]))
return
WindowList[WindowList.MovedWindow].x := x
WindowList[WindowList.MovedWindow].y := y
WindowList[WindowList.MovedWindow].w := w
WindowList[WindowList.MovedWindow].h := h
}
WM_POWERBROADCAST(wParam, lParam, msg)
{
if (wParam = 18)
AutoCloseWindowsUpdate(WinExist("Windows Update ahk_class #32770"))
}