-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGuiVar.ahk
172 lines (164 loc) · 4.02 KB
/
GuiVar.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
;{ GuiVar
; Fanatic Guru
; 2014 11 06
; Version: 1.1
;
; LIBRARY that uses hidden Gui windows to pass information between scripts.
;
;---------------------------------------------------------------------------------
; GuiVar_Set Set text content of a hidden Gui window
; GuiVar_Get Get text content of a hidden Gui window
; GuiVar_List Get name and text content of all hidden Gui window used by GuiVar
; GuiVar_Destroy Destroy hidden Gui window used by GuiVar
; GuiVar_DestroySetTimer Use SetTimer to check hidden Gui windows to destroy
;}
; FUNCTIONS
;{-----------------------------------------------
;
; GuiVar_Set
;
; Method:
; GuiVar_Set(Variable Name, Value)
;
; Parameters:
; 1) {Variable Name} name base of Gui window in which to store Value
; 2) {Value} text to store in Gui window
;
; Example:
; GuiVar_Set("Customer","Fanatic Guru")
;}
GuiVar_Set(Var,Value) {
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
if WinExist("GuiVar_" Var)
ControlSetText,, %Value%, GuiVar_%Var%
else
{
Gui, GuiVar_%Var%_GuiVar:Add, Text,, %Value%
Gui, GuiVar_%Var%_GuiVar:Show, Hide, GuiVar_%Var%_GuiVar
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
return
}
; GuiVar_Get
;
; Method:
; GuiVar_Get(Variable Name)
;
; Parameters:
; 1) {Variable Name} name base of Gui window from which to get text
;
; Returns:
; Text from Gui window
;
; Example:
; Current_Customer := GuiVar_Get("Customer")
;
GuiVar_Get(Var) {
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
ControlGetText, Value,, GuiVar_%Var%_GuiVar
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
return Value
}
; GuiVar_List
;
; Method:
; GuiVar_List(ByRef Array)
;
; Parameters:
; 1) {Array} variable in which to store Gui window data array
;
; Returns:
; number of elements in data array
;
; ByRef:
; Populates {Array} passed as parameter with Gui window data
;
GuiVar_List(ByRef Array) {
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
Array := {}
WinGet, WinList, List, GuiVar_
Loop, %WinList%
{
Hwnd := WinList%A_Index%
WinGetTitle, WinTitle, ahk_id %Hwnd%
ControlGetText, Value,, ahk_id %Hwnd%
WinTitle := SubStr(WinTitle, 8, StrLen(WinTitle)-14)
Array[WinTitle] := Value
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
return WinList
}
; GuiVar_Destroy
;
; Method:
; GuiVar_Get(Variable Name)
;
; Parameters:
; 1) {Variable Name} name base of Gui window to destroy
; default = "" destroys all Gui windows used by GuiVar
;
; Returns:
; Number of Gui windows destroyed
;
; Example:
; GuiVar_Destroy("Customer")
;
; Note: Only the script that first created a Gui can destroy that Gui
;
GuiVar_Destroy(Var := "") {
DetectHiddenWindows, % (Setting_A_DetectHiddenWindows := A_DetectHiddenWindows) ? "On" :
if Var
{
WinGet, WinList, ID, GuiVar_%Var%_GuiVar
WinList ? WinList := 1 : WinList := 0
Gui, GuiVar_%Var%_GuiVar:Destroy
}
else
{
WinGet, WinList, List, GuiVar_
Loop, %WinList%
{
Hwnd := WinList%A_Index%
WinGetTitle, WinTitle, ahk_id %Hwnd%
Gui, %WinTitle%:Destroy
}
}
DetectHiddenWindows, %Setting_A_DetectHiddenWindows%
return WinList
}
; GuiVar_DestroySetTimer
;
; Method:
; GuiVar_Get(Time, Value)
;
; Parameters:
; 1) {Time} time in ms to poll for Gui windows to destroy
; default = 1000
; 2) {Value} destroy all Gui windows with this value
; default = ""
;
; Returns:
; None
;
; Global:
; Creates a global variable named Value@GuiVar_DestroySetTimer
;
; Dependencies:
; GuiVar_List, GuiVar_Destroy
;
; Example:
; GuiVar_DestroySetTimer(10000, "Done") ; every 10 seconds destroy any GuiVar that equals "Done"
;
; Note: Only the script that first created a Gui can destroy that Gui
;
GuiVar_DestroySetTimer(Time := 1000, Value := "") {
global Value@GuiVar_DestroySetTimer := Value
SetTimer, GuiVar_DestroySetTimer, %Time%
return
GuiVar_DestroySetTimer:
GuiVar_List(List)
for var, value in List
if (value = Value@GuiVar_DestroySetTimer)
GuiVar_Destroy(Var)
return
}