Hello,
Is there a way to add a control button to a MsgBox which requires clicking for the script to continue?
For example, suppose you have a script which after several steps, displays a MsgBox and concurrently, pauses the script. Can the MsgBox include a "Continue" button which the user must click for the script to continue?
Thanks
Add control button to MsgBox
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Add control button to MsgBox
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: Add control button to MsgBox
In a way, yes. You can use ControlSetText to change the text of the message box buttons respectively to how they appear in the window. For example:
in a message box that has the option: 4, the Message box will have "Yes" and "No" buttons, the "Yes" button will be Button1, and the "No" button will be Button2.
I can give you a function to set the text of the buttons in respective order;
Just Specify the following in a script anywhere you want the Message box to appear and it will show with custom buttons:
Hope this helps.
in a message box that has the option: 4, the Message box will have "Yes" and "No" buttons, the "Yes" button will be Button1, and the "No" button will be Button2.
I can give you a function to set the text of the buttons in respective order;
Code: Select all
MsgBox(Message := "Press Ok to Continue.", Title := "", Type := 0, B1 := "", B2 := "", B3 := "", Time := "") {
If (Title = "")
Title := A_ScriptName
If (B1 != "") || (B2 != "") || (B3 != "")
SetTimer, ChangeButtonNames, -10
MsgBox, % Type, % Title, % Message, % Time
Return
ChangeButtonNames:
IfWinNotExist, %Title%
Return
WinActivate, % Title
ControlSetText, Button1, % (B1 = "") ? "Ok" : B1, % Title
Try ControlSetText, Button2, % (B2 = "") ? "Cancel" : B2, % Title
Try ControlSetText, Button3, % (B3 = "") ? "Close" : B3, % Title
Return
}
Code: Select all
MsgBox("Press ""Continue"" to Continue.",, 0, "Continue")
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Add control button to MsgBox
Hi.
Yes you can, but only with predefined buttons that the MsgBox offers.
The help file says
Now, if you click no, than the return command will be skipped and the code after will be processed.
Yes you can, but only with predefined buttons that the MsgBox offers.
The help file says
You can write code like this:To determine which button the user pressed in the most recent MsgBox, use the IfMsgBox command. For example:
MsgBox, 4,, Would you like to continue? (press Yes or No)
IfMsgBox Yes
MsgBox You pressed Yes.
else
MsgBox You pressed No.
Code: Select all
...
MsgBox, 4,, Would you like to abort?
IfMsgBox Yes
return
...
Einfach nur ein toller Typ.
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Re: Add control button to MsgBox
Thanks a bunch for the responses.
I'm pretty sure I understand your statement preceding the second (one-line) code box (ie Just Specify the following in a script anywhere...) — and I did get the MsgBox to appear — but I'm not sure what to do with the previous larger box of code. For example, suppose the following represents some script: and suppose you want to pause and bring up the MsgBox after Step A and get a user response before the script continues with Steps B, C & D. Then I presume, the one-line code is inserted like this:
Is that correct?
And if so, should your longer code be inserted before the script (ie above "F1::"), after the script (ie below "Return") or as a separate stand-alone script?
Or am I deep in left field picking dandelions (vs picking something else) and the correct answer is altogether different?
Thanks again
Sorry, but can you provide a bit more explanation re how to use this?Delta Pythagorean wrote:I can give you a function to set the text of the buttons in respective order;
Just Specify the following in a script anywhere you want the Message box to appear and it will show with custom buttons:Code: Select all
MsgBox(Message := "Press Ok to Continue.", Title := "", Type := 0, B1 := "", B2 := "", B3 := "", Time := "") { If (Title = "") Title := A_ScriptName If (B1 != "") || (B2 != "") || (B3 != "") SetTimer, ChangeButtonNames, -10 MsgBox, % Type, % Title, % Message, % Time Return ChangeButtonNames: IfWinNotExist, %Title% Return WinActivate, % Title ControlSetText, Button1, % (B1 = "") ? "Ok" : B1, % Title Try ControlSetText, Button2, % (B2 = "") ? "Cancel" : B2, % Title Try ControlSetText, Button3, % (B3 = "") ? "Close" : B3, % Title Return }
Code: Select all
MsgBox("Press ""Continue"" to Continue.",, 0, "Continue")
I'm pretty sure I understand your statement preceding the second (one-line) code box (ie Just Specify the following in a script anywhere...) — and I did get the MsgBox to appear — but I'm not sure what to do with the previous larger box of code. For example, suppose the following represents some script:
Code: Select all
F1::
Step A
Step B
Step C
Step D
Return
Code: Select all
F1::
Step A
MsgBox("Press ""Continue"" to Continue.",, 0, "Continue")
Step B
Step C
Step D
Return
And if so, should your longer code be inserted before the script (ie above "F1::"), after the script (ie below "Return") or as a separate stand-alone script?
Or am I deep in left field picking dandelions (vs picking something else) and the correct answer is altogether different?
Thanks again
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
- Delta Pythagorean
- Posts: 627
- Joined: 13 Feb 2017, 13:44
- Location: Somewhere in the US
- Contact:
Re: Add control button to MsgBox
The "longer code," can be put at the beginning or end of the script. The "longer code" is simply a function, functions can be put anywhere as long as it isn't mixed between another function or a label.WeThotUWasAToad wrote: And if so, should your longer code be inserted before the script (ie above "F1::"), after the script (ie below "Return") or as a separate stand-alone script?
So, in short, put it after the return in the hotkey it will work completely fine.
[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Add control button to MsgBox
Hi.
You choosed a very difficult example.
If it is not necessary, that the word continue is written on your button in the MsgBox make it easy and take this example:
Now, when you press No, your script will continue. Otherwise, you script will stop.
You choosed a very difficult example.
If it is not necessary, that the word continue is written on your button in the MsgBox make it easy and take this example:
Code: Select all
F1::
Step A
MsgBox, 4,, Would you like to abort?
IfMsgBox Yes
return
Step B
Step C
Step D
Return
Einfach nur ein toller Typ.
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Re: Add control button to MsgBox
[quote="divanebaba"]Yes you can, but only with predefined buttons that the MsgBox offers.[quote]
OK, I got this one to work:
It looks like I need to go read up on MsgBox's again because I did not realize it had those options.
Thanks
OK, I got this one to work:
Code: Select all
F1::
Send {Right 9}
Sleep, 500
MsgBox, 4,, Would you like to abort?
IfMsgBox Yes
ExitApp
Else
Send {Down 9}
Return
Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
-
- Posts: 312
- Joined: 19 Nov 2013, 08:44
Re: Add control button to MsgBox
Thanks for the clarification. It works like a charm:Delta Pythagorean wrote:The "longer code," can be put at the beginning or end of the script. The "longer code" is simply a function, functions can be put anywhere as long as it isn't mixed between another function or a label.WeThotUWasAToad wrote: And if so, should your longer code be inserted before the script (ie above "F1::"), after the script (ie below "Return") or as a separate stand-alone script?
So, in short, put it after the return in the hotkey it will work completely fine.
Code: Select all
F1::
Send {Right 9}
Sleep, 500
MsgBox("Press ""Continue"" to Continue.",, 0, "Continue")
;IfMsgBox Yes
; ExitApp
;Else
Send {Down 9}
Return
MsgBox(Message := "Press Ok to Continue.", Title := "", Type := 0, B1 := "", B2 := "", B3 := "", Time := "") {
If (Title = "")
Title := A_ScriptName
If (B1 != "") || (B2 != "") || (B3 != "")
SetTimer, ChangeButtonNames, -10
MsgBox, % Type, % Title, % Message, % Time
Return
ChangeButtonNames:
IfWinNotExist, %Title%
Return
WinActivate, % Title
ControlSetText, Button1, % (B1 = "") ? "Ok" : B1, % Title
Try ControlSetText, Button2, % (B2 = "") ? "Cancel" : B2, % Title
Try ControlSetText, Button3, % (B3 = "") ? "Close" : B3, % Title
Return
}
It's great to see different approaches to the same question.
Thanks a bunch to both of you for your assistance!
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.