-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathclass_TrayMinimizer.ahk
57 lines (52 loc) · 1.48 KB
/
class_TrayMinimizer.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
; Tray Minimizer class by evilC
; Based on Skan's MinimizeToTray
; Include this file, then call TrayMinimizer.Init()
; By default, will minimize Gui on start
; To disable, initialize with TrayMinimizer.Init(false)
class TrayMinimizer {
Init(minimizeOnStart := true){
; Store the HWND of the main Gui
Gui, +HwndhGui
this.hGui := hGui
; Create a BoundFunc for the Minimize handler
this.MinimizeFn := this.Minimize.Bind(this)
; Build tray menu
this.Menu("Tray","Nostandard")
this.Menu("Tray","Add","Restore", this.GuiShow.Bind(this))
this.Menu("Tray","Add")
this.Menu("Tray","Default","Restore")
this.Menu("Tray","Click",1)
this.Menu("Tray","Standard")
; Listen to messages to detect minimize click
OnMessage(0x112, this.WM_SYSCOMMAND.Bind(this))
if (minimizeOnStart){
this.Minimize()
}
}
; Detects click of Minimize button
WM_SYSCOMMAND(wParam){
If ( wParam == 61472 ) {
fn := this.MinimizeFn
; Async fire off the minimze function
SetTimer, % fn, -1
; Swallow this message (Stop window from doing normal minimze)
Return 0
}
}
; Handles transition from tray minimized to restored
GuiShow(){
; Remove tray icon - ToDo: should we not leave this?
this.Menu("Tray","NoIcon")
Gui, Show
}
; Minimizes to tray
Minimize() {
WinHide, % "ahk_id " this.hGui
this.Menu("Tray","Icon")
}
; Function wrapper for menu command
Menu( MenuName, Cmd, P3 := "", P4 := "", P5 := "" ) {
Menu, % MenuName, % Cmd, % P3, % P4, % P5
Return errorLevel
}
}