Displays the specified text in a small window containing one or more buttons (such as Yes and No).
MsgBox [, Options, Title, Text, Timeout]
If all the parameters are omitted, the MsgBox will display the text "Press OK to continue." Otherwise, this parameter is the text displayed inside the message box to instruct the user what to do, or to present information.
Escape sequences can be used to denote special characters. For example, `n indicates a linefeed character, which ends the current line and begins a new one. Thus, using text1`n`ntext2 would create a blank line between text1 and text2.
If Text is long, it can be broken up into several shorter lines by means of a continuation section, which might improve readability and maintainability.
Indicates the type of message box and the possible button combinations. If blank or omitted, it defaults to 0. See remarks for other allowed values.
This parameter will not be recognized if it is contained in a variable reference such as %option%. Instead, use a literal numeric value.
|Title||The title of the message box window. If omitted or blank, it defaults to the name of the script (without path).|
(optional) Timeout in seconds (can contain a decimal point but cannot be an expression). If this value exceeds 2147483 (24.8 days), it will be set to 2147483. After the timeout has elapsed the message box will be automatically closed and the IfMsgBox command will see the value TIMEOUT.
This command has smart comma handling, so it is usually not necessary to escape commas in the Text parameter.
The Options parameter can be a combination of the following values.
|OK (i.e. just an OK button is displayed)||0|
|Icon Hand (stop/error)||16|
|Icon Asterisk (info)||64|
|Make 2nd button the default||256|
|Make 3rd button the default||512|
|System Modal (always on top)||4096|
For example, to specify a SYSTEMMODAL box with the YES/NO buttons the Options value would be 4096+4 (4100).
To determine which button the user pressed in the most recent MsgBox, use the IfMsgBox command.
The text on the buttons can be changed by following this example.
The window shown by this command is a built-in feature of the operating system. As such, the X button (close) in the title bar is enabled only when certain buttons are present in the dialog: If there is only an OK button, clicking the X button is the same as pressing OK. Otherwise, the X button is disabled unless there is a Cancel button, in which case clicking the X is the same as pressing Cancel.
A GUI window may display a modal MsgBox by means of Gui +OwnDialogs. A modal MsgBox prevents the user from interacting with the GUI window until the MsgBox is dismissed. Note: In this case, it is not necessary to specify the System Modal or Task Modal options from the table above.
Pressing Control-C while a MsgBox window is active will copy its text to the clipboard. This applies to all MsgBoxes, not just those produced by AutoHotkey.
IfMsgBox, InputBox, FileSelectFile, FileSelectFolder, ToolTip, GUI
MsgBox, This is the 1-param method. Commas, do, not, need to be escaped. MsgBox, 4, , This is the 3-param method, non-escaped commas ok.`n`nContinue? IfMsgBox, No return MsgBox, 4, , This MsgBox will time out in 5 seconds. Continue?, 5 IfMsgBox, Timeout MsgBox, The previous MsgBox timed out. else IfMsgBox, No return ; By preceding any parameter with "% ", it becomes an expression. In the following example, ; math is performed, an array element is accessed, and a function is called. All of these ; items are concatenated via the "." operator to form a single string displayed by MsgBox: MsgBox % "New width for object #" . A_Index . " is: " . RestrictWidth(ObjectWidth%A_Index% * ScalingFactor)