AutoIt MsgBox Function

The MsgBox function is used to show small dialog boxes to the user.

4295 views

Created: 2017-01-09 04:15

The AutoIt MsgBox function is used to create message boxes for the user to interact with. It can both be used to show error messages – typically not requiring a response from the user – and to create dialog boxes accepting user input.

You can also use MsgBox to test your scripts while coding.

The MsgBox takes three required arguments, and two optional arguments. The first of the arguments is a flag that controls the type of message box to be created, the second is the window title of the message box, and the third is the actual text.

Parameters

flagRequiredThe Message Box type.
titleRequiredThe window title of the message box.
textRequiredThe content of the message box.
timeoutOptionalTime in seconds to display the message box, default is no timeout.
hwndOptionalThe window handle of the parant

Return Values

The return values from pressing the different buttons are as follows.

Button:Return Value:
OK1
CANCEL2
ABORT3
RETRY4
IGNORE5
YES6
NO7
TRY AGAIN **10
CONTINUE **11

MsgBox Flag Combinations

The MsgBox flag accepts a combination of values from this section. You can see examples of how this can be used in the examples section on this page.

Normal values..

DecimalHexadecimalResult
00x0OK
10x1OK, Cancel
20x2Abort, Retry, and Ignore
30x3Yes, No, and Cancel
40x4Yes, No
50x5Retry, Cancel
60x6Cancel, Try Again, and Continue

Icon flag values..

DecimalHexadecimalResult
00x0No Icon
160x10Stop-sign icon
320x20Question-mark icon
480x30Exclamation-point icon
640x40Information-sign icon consisting of an 'i' in a circle

Default button flag values..

DecimalHexadecimalResult
00x0First button is default button
2560x10Second button is default button
5120x20Third button is default button

Default button flag values..

DecimalHexadecimalResult
00x0First button is default button
2560x10Second button is default button
5120x20Third button is default button

Modality flag values..

DecimalHexadecimalResult
00x0Application
40960x1000System modal
81920x2000Task modal

Miscellaneous flag values..

DecimalHexadecimalResult
00x0nothing else special
2621440x40000The MsgBox will have the top-most attribute set.
5242880x80000The title and text of the MsgBox will be right-justified.

MsgBox Examples

To combine values, you may use the plus (+) sign – so to give a standard MsgBox containing a OK and a Cancel button a Icon, you may use something like:

MsgBox(4096+1, "Test", "Just a test message box with icon")

The purpose of Modality flags is however not to display an icon, but the example shows how you can combine flags using the plus operator. If you want more control over your message boxes, such as the ability to create a custom icon, you should create your own GUIs instead.

Tell us what you think: