While using MsgBoxEx in my script I noticed that the GUI was hiding it's owner when using timeout.
So I changed the line Gui Submit at the end in the function to the following.
Code: Select all
Gui Submit, % Owner ? "NoHide" : ""
Have Fun,
Megnatar
Code: Select all
Gui Submit, % Owner ? "NoHide" : ""
Code: Select all
#NoEnv
#SingleInstance force
#KeyHistory 0
SetBatchLines -1
Listlines off
OnTop := 1
GUI % "+LastFound " (OnTop ? "+" : "-") "AlwaysOnTop +OwnDialogs +hWndhScriptGui -Theme"
Gui add, button, w130, MsgBox Test
Gui, Show
Return
ButtonMsgBoxtest:
Text := "Work in progress`nNot Implemented yet."
MsgBoxEx(Text, "ToDo", "Close", [65, "imageres.dll"], "", "AlwaysOnTop", hScriptGui, 5)
Return
GuiClose:
GuiEscape:
Exitapp
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, 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
DetectHiddenWindows % A_DetectHiddenWindows = "Off" ? "On" : A_DetectHiddenWindows
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
DetectHiddenWindows % A_DetectHiddenWindows = "Off" ? "On" : "Off"
Gui Show,, % Timeout ? Title " : " Timeout : Title
Gui +SysMenu %Styles%
If (Owner) {
WinSet Disable,, ahk_id %Owner%
}
If (Timeout) {
CountDown := Round(Timeout) * 1000
SetTimer MsgBoxExTIMEOUT, 1000
}
GuiControl Focus, f
Gui Font
WinWaitClose ahk_id %hWnd%
Return RetVal
MsgBoxExBUTTON:
MsgBoxExESCAPE:
MsgBoxExCLOSE:
MsgBoxExTIMEOUT:
If (A_ThisLabel == "MsgBoxExTIMEOUT") {
if (CountDown := Round(CountDown) - 1000) {
WinSetTitle ahk_id %hWnd%, , % Title " : " CountDown // 1000
Return
}
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, nohide ; Never hide main GUI instance when submitting changes to it.
Gui Submit, % Owner ? "NoHide" : "" ; Only hide when it's not owned and timeout is used.
Gui %hWnd%: Destroy
Return
}
Code: Select all
#NoEnv
#SingleInstance force
#KeyHistory 0
SetBatchLines -1
Listlines off
OnTop := 1
GUI % "+LastFound " (OnTop ? "+" : "-") "AlwaysOnTop +OwnDialogs +hWndhScriptGui -Theme"
Gui add, button, w130, MsgBox Test
Gui, Show
Return
ButtonMsgBoxtest:
Text := "Work in progress`nNot Implemented yet."
MsgBoxEx(Text, "ToDo" count, "Close", [65, "imageres.dll"], "", "AlwaysOnTop", hScriptGui, 5)
Return
GuiClose:
GuiEscape:
Exitapp
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
}
You're welcome. Yes that crossed my mind to, but I was not sure "hiding" was a choice or something overlooked.
Users browsing this forum: No registered users and 9 guests