-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathMsgBoxEx.ahk
94 lines (79 loc) · 2.92 KB
/
MsgBoxEx.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
MsgBoxEx(Text, Title := "", Buttons := "", Icon := "", ByRef CheckText := "", Styles := "", Owner := "", Timeout := "", FontOptions := "", FontName := "", BGColor := "", Callback := "") {
Static hWnd, y2, p, px, pw, c, cw, cy, ch, f, o, gL, hBtn, lb, DHW, ww, Off, k, v, RetVal
Static Sound := {2: "*48", 4: "*16", 5: "*64"}
Gui New, hWndhWnd LabelMsgBoxEx -0xA0000
Gui % (Owner) ? "+Owner" . Owner : ""
Gui Font
Gui Font, % (FontOptions) ? FontOptions : "s9", % (FontName) ? FontName : "Segoe UI"
Gui Color, % (BGColor) ? BGColor : "White"
Gui Margin, 10, 12
If (IsObject(Icon)) {
Gui Add, Picture, % "x20 y24 w32 h32 Icon" . Icon[1], % (Icon[2] != "") ? Icon[2] : "shell32.dll"
} Else If (Icon + 0) {
Gui Add, Picture, x20 y24 Icon%Icon% w32 h32, user32.dll
SoundPlay % Sound[Icon]
}
Gui Add, Link, % "x" . (Icon ? 65 : 20) . " y" . (InStr(Text, "`n") ? 24 : 32) . " vc", %Text%
GuicontrolGet c, Pos
GuiControl Move, c, % "w" . (cw + 30)
y2 := (cy + ch < 52) ? 90 : cy + ch + 34
Gui Add, Text, vf -Background ; Footer
Gui Font
Gui Font, s9, Segoe UI
px := 42
If (CheckText != "") {
CheckText := StrReplace(CheckText, "*",, ErrorLevel)
Gui Add, CheckBox, vCheckText x12 y%y2% h26 -Wrap -Background AltSubmit Checked%ErrorLevel%, %CheckText%
GuicontrolGet p, Pos, CheckText
px := px + pw + 10
}
o := {}
Loop Parse, Buttons, |, *
{
gL := (Callback != "" && InStr(A_LoopField, "...")) ? Callback : "MsgBoxExBUTTON"
Gui Add, Button, hWndhBtn g%gL% x%px% w90 y%y2% h26 -Wrap, %A_Loopfield%
lb := hBtn
o[hBtn] := px
px += 98
}
GuiControl +Default, % (RegExMatch(Buttons, "([^\*\|]*)\*", Match)) ? Match1 : StrSplit(Buttons, "|")[1]
Gui Show, Autosize Center Hide, %Title%
DHW := A_DetectHiddenWindows
DetectHiddenWindows On
WinGetPos,,, ww,, ahk_id %hWnd%
GuiControlGet p, Pos, %lb% ; Last button
Off := ww - (((px + pw + 14) * A_ScreenDPI) // 96)
For k, v in o {
GuiControl Move, %k%, % "x" . (v + Off)
}
Guicontrol MoveDraw, f, % "x-1 y" . (y2 - 10) . " w" . ww . " h" . 48
Gui Show
Gui +SysMenu %Styles%
DetectHiddenWindows %DHW%
If (Timeout) {
SetTimer MsgBoxExTIMEOUT, % Round(Timeout) * 1000
}
If (Owner) {
WinSet Disable,, ahk_id %Owner%
}
GuiControl Focus, f
Gui Font
WinWaitClose ahk_id %hWnd%
Return RetVal
MsgBoxExESCAPE:
MsgBoxExCLOSE:
MsgBoxExTIMEOUT:
MsgBoxExBUTTON:
SetTimer MsgBoxExTIMEOUT, Delete
If (A_ThisLabel == "MsgBoxExBUTTON") {
RetVal := StrReplace(A_GuiControl, "&")
} Else {
RetVal := (A_ThisLabel == "MsgBoxExTIMEOUT") ? "Timeout" : "Cancel"
}
If (Owner) {
WinSet Enable,, ahk_id %Owner%
}
Gui Submit
Gui %hWnd%: Destroy
Return
}