-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathInfoGUI.ahk
603 lines (540 loc) · 18.3 KB
/
InfoGUI.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
;-----------------------------
;
; Function: InfoGUI
;
; Description:
;
; This function displays a simple read-only text window. See the "Processing
; And Usage Notes" section for more information.
;
;
; Parameters:
;
; p_Owner - GUI owner of the InfoGUI window. [Optional] The default is 0 (no
; owner). If the value is not an integer between 1 and 99, the
; AlwaysOnTop attribute is added to the InfoGUI window to make sure that
; the window is not lost.
;
; p_Text - The text that is displayed in the information window.
;
; p_Title - Window title. [Optional] The default is the current script name
; sans the extension.
;
; p_GUIOptions - GUI Options. [Optional] The default are the options in the
; s_DefaultGUIOptions variable (if any). Some common options:
;
; (start code)
; Option Description
; ------ -----------
; Border Also known as "+Border". If used with the "-Caption"
; option, creates a thin border around the window.
;
; -Border If used without the "-Caption" option, removes the title
; bar from the window and creates a thick border around
; the window.
;
; -Caption Removes the title bar from the window.
;
; -MaximizeBox Disables the maximize button in the title bar (if it
; exists). This option is commonly used with the +Resize
; option.
;
; -MinimizeBox Disables the minimize button in the title bar (if it
; exists).
;
; Resize Also known as "+Resize". Makes the window resizable and
; enables the maximize button (if it exists). See the
; "-MaximizeBox" option. This option is best used with
; the "Edit" object type and when the text is long or
; dynamic.
;
; -SysMenu This option removes the following from the title bar:
; System Menu, Program icon, Minimize button, Maximize
; button, And Close button.
;
; ToolWindow Also know as "+ToolWindow". Creates a narrow title bar
; and removes the minimize and maximize buttons (if they
; exist).
; (end)
;
; To use more than one option, include a space between each option. For
; example: "+Resize -MaximizeBox".
;
; To insure that InfoGUI window is modal (and/or acts like it), the
; "-MinimizeBox" option is always added to this parameter.
;
; For more information, see the AutoHotkey documentation (Keyword: GUI,
; Section: Options)
;
; p_ObjectType - Object Type. [Optional] Valid values are "Edit" and "Text".
; The "Edit" object type (the default) is selectable (the users can mark
; and copy) and a vertical scroll bar is created so the user can scroll
; through large amounts of text. The "Resize" GUI option is sometimes
; used with this object type. The "Text" object type is not selectable and
; a scroll bar is not created. However, the entire InfoGUI window can be
; moved by dragging anywhere inside of the text object.
;
;
; p_ObjectOptions - Object options. [Optional] The default are the options in
; the s_DefaultObjectOptions variable (if any) Some common options
; include the following (not case sensitive):
;
; (start code)
; Option Description
; ------ -----------
; Border Also known as "+Border". This option creates a thin-line
; border around the object. Depending on what other parameter
; values are defined (or not defined), the border may give the
; object the illusion that it is indented (sunken).
;
; c{Color} Font color. "Color" is an HTML color name or 6-digit hex
; RGB color value. If this option is used, it will override
; the "color" option of the p_FontOptions parameter (if
; defined).
;
; Center Also known as "+Center". Centers the text within its
; available width.
;
; h{pixels} Height (in pixels) of the object. This option is NOT
; recommended. Use the r{#OfRows} option instead.
;
; r{#OfRows} Rows of text to display.
;
; Right Also known as "+Right". Right-justifies the text within its
; available width.
;
; -VScroll Removes the vertical scroll bar ("Edit" object type only).
;
; w{pixels} Width (in pixels) of the object.
; (end)
;
; To use more than one option, include a space between each option.
; Example: "w200 r20 Border".
;
; If the "width" option is not specified by the developer or by default,
; the width of the object is determined by the width of the lines of text
; in the p_Text parameter.
;
; If the "height" or "row" options are not specified by the developer or
; by default, the height of the object is determined by the number of
; lines of text in the p_Text parameter.
;
; For more information, see the AutoHotkey documentation (Keyword: GUI,
; Section: Positioning and Sizing of Controls)
;
; p_BGColor - Sets the background color of the object. [Optional] The default
; is blank (uses the system default color). To set, specify one of the 16
; primary HTML color names or a 6-digit hex RGB color value. For more
; information, see the AutoHotkey documentation (Keyword: color names)
;
; p_Font - The text font. [Optional] The default is blank (uses the system
; default font). For a list of available font names, see the AutoHotkey
; documentation (Keyword: Fonts)
;
; p_FontOptions - Font Options. [Optional] The default is blank (uses the
; system defaults). The following options are available (not case
; sensitive):
;
; (start code)
; Option Description
; ------ -----------
; Bold
;
; c{Color} Font color. "Color" is an HTML color name or 6-digit hex
; RGB color value.
;
; Italic
;
; s{Size} Font size in points.
;
; Strike
;
; Underline
; (end)
;
; To use more than one option, include a space between each option.
; Example: "cBlue s10 bold underline".
;
; For more information, see the AutoHotkey documentation (Keyword: GUI,
; Section: Font).
;
; p_Timeout - Window timeout (in seconds). [Optional] The default is blank
; (no timeout).
;
;
; Returns:
;
; True if the InfoGUI window was created and closed successfully. False if
; the function was unable to create the InfoGUI window (very rare) or if a
; InfoGUI window is already open when the function is called. The second
; condition can occur if the script contains multiple triggers (usually
; hotkeys and/or buttons) that call the InfoGUI function.
;
;
; Calls To Other Functions:
;
; PopupXY (optional)
;
;
; Processing And Usage Notes:
; A few notes...
;
; * This function does not return until the InfoGUI window is closed.
;
; * If a GUI number (integer between 1 and 99) is specified for the p_Owner
; parameter, the InfoGUI window is made modal. If a non-modal window is
; desired, set p_Owner to the window's handle or to 0 (if the PopupXY
; function is not included). Programming note: Ownership is only assigned
; if p_Owner contains a GUI number. This limitation may change in the
; future.
;
; * Because of the large number of possible values, many of the function
; parameters are not checked for integrity. Most of the time, invalid
; values are simply ignored. However, invalid values may cause the script
; to fail. Be sure to carefully select the parameter values and test
; your script thoroughly.
;
;
; Customizing:
;
; This function can be customized in an infinite number of ways. The quickest
; and most effective customization would be to change the default values for
; the parameters. Note that default values were purposely excluded from the
; function definition so that the default values would not have to be changed
; twice -- once in the function definition and again in the "Parameters"
; section of the code.
;
;-------------------------------------------------------------------------------
InfoGUI(p_Owner=""
,p_Text=""
,p_Title=""
,p_GUIOptions=""
,p_ObjectType=""
,p_ObjectOptions=""
,p_BGColor=""
,p_Font=""
,p_FontOptions=""
,p_Timeout="")
{
;[====================]
;[ Static variables ]
;[====================]
Static s_GUI:=0
;-- This variable stores the currently active GUI. If not zero
; when entering the function, the GUI is currently showing.
,s_StartGUI:=56
;-- Default starting GUI window number for InfoGUI window.
; Change if desired.
,s_PopupXY_Function:="PopupXY"
;-- Name of the PopupXY function. Defined as a variable so that
; function will use if the "PopupXY" function is included but
; will not fail if it's not.
,s_DefaultGUIOptions:=""
;-- Default GUI options. Leave blank for no defaults.
,s_DefaultObjectOptions:="w500 r15"
;-- Default object options. Set to blank for no defaults.
;[===========================]
;[ Window already showing? ]
;[===========================]
if s_GUI
{
outputdebug,
(ltrim join`s
End Func: %A_ThisFunc% -
A %A_ThisFunc% window already exists.
)
Return False
}
;[==================]
;[ Parameters ]
;[ (Set defaults) ]
;[==================]
;---------
;-- Owner
;---------
p_Owner=%p_Owner% ;-- AutoTrim
if p_Owner is not Integer
p_Owner:=0
;-- Owner window exist?
if p_Owner Between 1 and 99
{
gui %p_Owner%:+LastFoundExist
IfWinNotExist
{
outputdebug,
(ltrim join`s
Function: %A_ThisFunc% -
Owner window does not exist. p_Owner=%p_Owner%
)
p_Owner:=0
}
}
;---------
;-- Title
;---------
p_Title=%p_Title% ;-- AutoTrim
SplitPath A_ScriptName,,,,l_ScriptName
if StrLen(p_Title)=0
p_Title:=l_ScriptName
else
{
;-- Append to script name if p_title begins with "++"?
if SubStr(p_Title,1,2)="++"
{
StringTrimLeft p_Title,p_Title,2
p_Title:=l_ScriptName . A_Space . p_Title
}
}
;---------------
;-- GUI Options
;---------------
p_GUIOptions=%p_GUIOptions% ;-- AutoTrim
if p_GUIOptions is Space
p_GUIOptions:=s_DefaultGUIOptions
p_GUIOptions:=p_GUIOptions . " -MinimizeBox"
;---------------
;-- Object Type
;---------------
p_ObjectType=%p_ObjectType% ;-- AutoTrim
if p_ObjectType not in Edit,Text
p_ObjectType:="Edit"
;-- Identify Move command and ClassNN
l_MoveCmd:="Move"
l_ClassNN:="Edit1"
if (p_ObjectType="Text")
{
l_MoveCmd:="MoveDraw"
l_ClassNN:="Static1"
}
;------------------
;-- Object options
;------------------
p_ObjectOptions=%p_ObjectOptions% ;-- AutoTrim
if p_ObjectOptions is Space
p_ObjectOptions:=s_DefaultObjectOptions
;---------
;-- Misc.
;---------
p_BGColor=%p_BGColor% ;-- AutoTrim
p_Font=%p_Font% ;-- AutoTrim
p_FontOptions=%p_FontOptions% ;-- AutoTrim
;-----------
;-- Timeout
;-----------
p_Timeout=%p_Timeout% ;-- Autotrim
if p_Timeout is Number
p_Timeout:=p_Timeout*1000
else
p_Timeout:=""
;[==============================]
;[ Find available window ]
;[ (Starting with s_StartGUI) ]
;[==============================]
s_GUI:=s_StartGUI
Loop
{
;-- Window available?
gui %s_GUI%:+LastFoundExist
IfWinNotExist
Break
;-- Nothing available?
if (s_GUI=99)
{
MsgBox
,262160
;-- 262160=0 (OK button) + 16 (Error icon) + 262144 (AOT)
,%A_ThisFunc% Error,
(ltrim join`s
Unable to create a %A_ThisFunc% window. GUI windows
%s_StartGUI% to 99 are already in use. %A_Space%
)
Return False
}
;-- Increment window number
s_GUI++
}
;[================]
;[ Context Menu ]
;[================]
;-- Create stub (needed for the 1st call)
Menu InfoGUI_ContextMenu,Add
;-- Clear menu
Menu InfoGUI_ContextMenu,DeleteAll
;-- Context menu items
Menu InfoGUI_ContextMenu
,Add
,&Copy All`tCtrl+C
,InfoGUI_CopyToClipboard
Menu InfoGUI_ContextMenu,Add
Menu InfoGUI_ContextMenu
,Add
,Close`tAlt+F4
,InfoGUI_Close
;[=============]
;[ Build GUI ]
;[=============]
;-- Owner?
if p_Owner Between 1 and 99
{
;-- Disable Owner, give ownership of GUI to Owner
gui %p_Owner%:+Disabled ;-- Disable Owner window
gui %s_GUI%:+Owner%p_Owner% ;-- Set ownership
}
else
gui %s_GUI%:+Owner ;-- Give ownership to the script window
;-- GUI Options
gui %s_GUI%:Margin,0,0
gui %s_GUI%:+LabelInfoGUI_ %p_GUIOptions%
if p_Owner not Between 1 and 99
gui %s_GUI%:+AlwaysOnTop
;-- Set background color
if p_BGColor is not Space
gui %s_GUI%:Color,%p_BGColor%
;-- Set font and font options
gui %s_GUI%:Font,%p_FontOptions%,%p_Font%
;-- Create object (Text or Edit)
Static InfoGUI_Object
gui %s_GUI%:Add
,%p_ObjectType%
,%p_ObjectOptions%
|| +ReadOnly
|| vInfoGUI_Object
|| gInfoGUI_Move
,%p_Text%
;-- Note: The object is populated here just in case the contents are
; needed to determine the width and/or height of the control.
;-- Reset font to system default
gui %s_GUI%:Font
;-- Clear object
GUIControl %s_GUI%:,InfoGUI_Object,%A_Space%
;-- Note: Object is cleared here so that the user will not experience a
; Screen flicker ("Edit" object type only) when the window is shown.
;-- Collect window handle
gui %s_GUI%:+LastFound
WinGet l_InfoGUI_hWnd,ID
GroupAdd InfoGUI_Group,ahk_id %l_InfoGUI_hWnd%
;-- Show it
if p_Owner and IsFunc(s_PopupXY_Function)
{
;-- Render, identify center position, and show
gui %s_GUI%:Show,Hide,%p_Title%
%s_PopupXY_Function%(p_Owner,l_InfoGUI_hWnd,PosX,PosY)
gui %s_GUI%:Show,x%PosX% y%PosY%
}
else
gui %s_GUI%:Show,,%p_Title%
;-- Populate object
GUIControl %s_GUI%:,InfoGUI_Object,%p_Text%
;-- Note: Object is (re)populated after the window is displayed so that
; the contents are not selected.
;[====================]
;[ Timer and Hotkey ]
;[====================]
if p_Timeout
SetTimer InfoGUI_Timer,%p_Timeout%
if (p_ObjectType="Text")
{
Hotkey IfWinActive,ahk_group InfoGUI_Group
Hotkey ^c,InfoGUI_CopyToClipboard,On
Hotkey IfWinActive
}
;[=====================]
;[ Wait until window ]
;[ is closed ]
;[=====================]
WinWaitClose ahk_id %l_InfoGUI_hWnd%
Return True ;-- End of function
;*****************************
;* *
;* *
;* Subroutines *
;* (InfoGUI) *
;* *
;* *
;*****************************
;***************************
;* *
;* Copy to Clipboard *
;* *
;***************************
InfoGUI_CopyToClipboard:
;-- Add CR if/where needed
l_Text:=p_Text
if l_Text not Contains `r`n
StringReplace l_Text,l_Text,`n,`r`n,All
;-- Add final CR+LF if needed
if SubStr(l_Text,0)<>"`n"
l_Text.="`r`n"
;-- Paste to clipboard
Clipboard:=l_Text
;-- Tooltip
ToolTip All text copied to the clipboard.,25,40
SetTimer InfoGUI_HideToolTip,4000
return
;**********************
;* *
;* Context menu *
;* *
;**********************
InfoGUI_ContextMenu:
;-- Show. Note: This menu will only show if object type is "Text"
Menu InfoGUI_ContextMenu,Show,%A_GUIX%,%A_GUIY%
return
;**********************
;* *
;* Hide Tooltip *
;* *
;**********************
InfoGUI_HideToolTip:
SetTimer %A_ThisLabel%,Off
ToolTip
return
;**************
;* *
;* Move *
;* *
;**************
InfoGUI_Move:
PostMessage 0xA1,2 ;-- SKAN trick. Only works if object type is "Text"
return
;****************
;* *
;* Resize *
;* *
;****************
InfoGUI_Size:
if (A_EventInfo=1) ;-- Minimize
return
;-- Move it
GUIControl
,%s_GUI%:%l_MoveCmd%
,%l_ClassNN%
,% "w" . A_GUIWidth . " h" . A_GUIHeight
return
;***********************
;* *
;* Close up shop *
;* *
;***********************
InfoGUI_Timer:
InfoGUI_Escape:
InfoGUI_Close:
;-- Turn off timer
SetTimer InfoGUI_Timer,Off
;-- Hide Tooltip
gosub InfoGUI_HideToolTip
;-- Disable hotkey
if (p_ObjectType="Text")
{
Hotkey IfWinActive,ahk_group InfoGUI_Group
Hotkey ^c,InfoGUI_CopyToClipboard,Off
Hotkey IfWinActive
}
;-- Enable Owner window
if p_Owner Between 1 and 99
gui %p_Owner%:-Disabled
;-- Destroy the InfoGUI window so that it can be be reused
gui %s_GUI%:Destroy
s_GUI:=0
return ;-- End of subroutines
}