AutoIt MsgBox Function
The MsgBox function is used to show small dialog boxes to the user.
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
flag | Required | The Message Box type. |
title | Required | The window title of the message box. |
text | Required | The content of the message box. |
timeout | Optional | Time in seconds to display the message box, default is no timeout. |
hwnd | Optional | The window handle of the parant |
Return Values
The return values from pressing the different buttons are as follows.
Button: | Return Value: |
---|---|
OK | 1 |
CANCEL | 2 |
ABORT | 3 |
RETRY | 4 |
IGNORE | 5 |
YES | 6 |
NO | 7 |
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..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | OK |
1 | 0x1 | OK, Cancel |
2 | 0x2 | Abort, Retry, and Ignore |
3 | 0x3 | Yes, No, and Cancel |
4 | 0x4 | Yes, No |
5 | 0x5 | Retry, Cancel |
6 | 0x6 | Cancel, Try Again, and Continue |
Icon flag values..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | No Icon |
16 | 0x10 | Stop-sign icon |
32 | 0x20 | Question-mark icon |
48 | 0x30 | Exclamation-point icon |
64 | 0x40 | Information-sign icon consisting of an 'i' in a circle |
Default button flag values..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | First button is default button |
256 | 0x10 | Second button is default button |
512 | 0x20 | Third button is default button |
Default button flag values..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | First button is default button |
256 | 0x10 | Second button is default button |
512 | 0x20 | Third button is default button |
Modality flag values..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | Application |
4096 | 0x1000 | System modal |
8192 | 0x2000 | Task modal |
Miscellaneous flag values..
Decimal | Hexadecimal | Result |
---|---|---|
0 | 0x0 | nothing else special |
262144 | 0x40000 | The MsgBox will have the top-most attribute set. |
524288 | 0x80000 | The 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: