-
Notifications
You must be signed in to change notification settings - Fork 72
/
GuiWnd.ahk
242 lines (203 loc) · 3.98 KB
/
GuiWnd.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
class GuiWnd
{
static Windows := {}
__New(title:="", options:="", FuncPrefixOrObj:="")
{
Gui, New, +LastFound %options% +LabelGWnd_On, %title%
this.__Handle := WinExist()+0
this.__FuncPrefixOrObj := FuncPrefixOrObj
GuiWnd.Windows[this.Handle] := &this
}
__Delete()
{
if (this.Handle && DlLCall("IsWindow", "Ptr", this.Handle))
this.Destroy()
}
__Call(method, args*)
{
if ( InStr(method, "Add")==1 && StrLen(method)>3 )
return this.Add(SubStr(method, 4), args*)
}
Handle {
get {
return this.__Handle + 0
}
set {
throw Exception("This property is read-only", -1, "Handle")
}
}
Options {
set {
h := this.Handle
Gui, %h%:%value%
return value
}
}
Add(CtlType, options:="", text:="")
{
global ; for control's associated variable(s)
local h, hCtl
h := this.Handle
Gui, %h%:Add, %CtlType%, %options% +HwndhCtl, %text%
return hCtl
}
Show(options:="", title:="")
{
h := this.Handle
Gui, %h%:Show, %options%, %title%
}
Destroy()
{
h := this.Handle
Gui, %h%:Destroy
ObjDelete(GuiWnd.Windows, h)
this.__Handle := ""
}
SetOptions(options:="")
{
h := this.Handle
Gui, %h%:%options%
}
SetFont(FontOptions:="", FontName:="")
{
h := this.Handle
Gui, %h%:Font, %FontOptions%, %FontName%
}
BgColor {
set {
h := this.Handle
Gui, %h%:Color, %value%
return value
}
}
CtlColor {
set {
h := this.Handle
Gui, %h%:Color,, %value%
return value
}
}
Margin[arg:="XY"] {
set {
h := this.Handle
X := Trim(arg, " `tY")="X" ? value : ""
Y := Trim(arg, " `tX")="Y" ? value : ""
Gui, %h%:Margin, %X%, %Y%
return value
}
}
Menu {
set {
h := this.Handle
Gui, %h%:Menu, %value%
return value
}
}
Hide()
{
h := this.Handle
Gui, %h%:Hide
}
Minimize()
{
h := this.Handle
Gui, %h%:Minimize
}
Maximize()
{
h := this.Handle
Gui, %h%:Maximize
}
Restore()
{
h := this.Handle
Gui, %h%:Restore
}
Flash(flash:=true)
{
h := this.Handle
OnOrOff := (flash && flash!="Off") ? "On" : "Off"
Gui, %h%:Flash, %OnOrOff%
}
SetAsDefault()
{
h := this.Handle
Gui, %h%:Default
}
FocusedCtl {
get {
h := this.Handle
GuiControlGet, FocusedCtl, %h%:Focus
GuiControlGet, hFocusedCtl, %h%:Hwnd, %FocusedCtl%
return hFocusedCtl+0
}
}
OnClose()
{
this.Destroy()
prev_DHW := A_DetectHiddenWindows
DetectHiddenWindows, On
static PID := DllCall("GetCurrentProcessId")
if !WinExist("ahk_class AutoHotkeyGUI ahk_pid " . PID)
SetTimer, gwnd_exit, -1
DetectHiddenWindows, %prev_DHW%
return
gwnd_exit:
ExitApp
}
_OnEvent(event, args*)
{
FuncPrefixOrObj := this.__FuncPrefixOrObj
; Similar to ComObjConnect
if IsObject(FuncPrefixOrObj)
return FuncPrefixOrObj[event](this, args*)
; +Label<LabelorFuncPrefix>
else if fn := Func(FuncPrefixOrObj . event)
return fn.Call(this, args*)
; Subclassing
else
return this[event](args*)
}
Pos[arg:="", client:=false] {
get {
static RECT
if !VarSetCapacity(RECT)
VarSetCapacity(RECT, 16, 0)
DllCall(client ? "GetClientRect" : "GetWindowRect", "Ptr", this.Handle, "Ptr", &RECT)
w := NumGet(RECT, 8, "Int") - x := NumGet(RECT, 0, "Int")
h := NumGet(RECT, 12, "Int") - y := NumGet(RECT, 4, "Int")
return ((StrLen(arg:=Trim(arg, " `t`r`n"))==1) && InStr("XYWH", arg)) ? %arg% : { X:x, Y:y, W:w, H:h }
}
}
ClientPos[arg:=""] {
get {
return this.Pos[arg, true]
}
}
}
GWnd_Get(h)
{
if ( pThis := GuiWnd.Windows[h + 0] )
&& ( NumGet(pThis+0) == NumGet(&(o := {})) ) ; make sure it's an object pointer
return Object(pThis)
}
GWnd_OnClose(h)
{
return GuiWnd._OnEvent.Call(GWnd_Get(h), "OnClose")
}
GWnd_OnEscape(h)
{
return GuiWnd._OnEvent.Call(GWnd_Get(h), "OnEscape")
}
GWnd_OnSize(h, args*)
{
return GuiWnd._OnEvent.Call(GWnd_Get(h), "OnSize", args*)
}
GWnd_OnContextMenu(h, args*)
{
return GuiWnd._OnEvent.Call(GWnd_Get(h), "OnContextMenu", args*)
}
GWnd_OnDropFiles(h, args*)
{
return GuiWnd._OnEvent.Call(GWnd_Get(h), "OnDropFiles", args*)
}