Modal MsgBox Styles: Difference between revisions
No edit summary |
m (Added wiki headers organized in a hopefully sensible manner.) |
||
Line 1: | Line 1: | ||
''MsgBox'' is a blocking function | =Modal MsgBox Styles= | ||
''MsgBox'' is a blocking function which means that a script pauses until a button on the ''MsgBox'' is pressed at which point the function terminates with a return value which you can use in a decision structure of some kind. Your main GUI appears unresponsive until the ''MsgBox'' is cleared. However, things are not quite that simple because the ''MsgBox'' can be set as '''Application, System''' or '''Task Modal'''. Although the values needed to set these styles are given in the Helpfile, it does not actually explain the difference between them. | |||
==Application== | |||
This is the default setting. In this case your GUI will react to mouse clicks and will even retake focus from the ''MsgBox'', but will not act on the clicks until the ''MsgBox'' is cleared. Try closing the main GUI while the ''MsgBox'' is displayed - it will not close unless you clear the ''Msgbox'' first: | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
#include <GUIConstantsEx.au3> | #include <GUIConstantsEx.au3> | ||
Line 19: | Line 18: | ||
EndSwitch | EndSwitch | ||
WEnd | WEnd | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==System Modal== | |||
Now the ''MsgBox'' remains in view even if the main GUI regains focus although the main GUI appears inactive the GUI. However if the main GUI is closed this will again occur as soon as the ''MsgBox'' is cleared. | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
#include <GUIConstantsEx.au3> | #include <GUIConstantsEx.au3> | ||
Line 38: | Line 37: | ||
WEnd | WEnd | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Task Modal== | |||
Now we get to the real deal - you cannot action anything on the main GUI until the ''MsgBox'' is cleared. So you cannot close the main GUI - or do anything else with it at all! | |||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
#include <GUIConstantsEx.au3> | #include <GUIConstantsEx.au3> | ||
Line 55: | Line 54: | ||
EndSwitch | EndSwitch | ||
WEnd | WEnd | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Now all you have to do is choose which type best suits your needs! | Now all you have to do is choose which type best suits your needs! | ||
=An Added Extra= | |||
Another way to prevent the GUI from being actioned while the ''MsgBox'' is present is to set the "''parent''" parameter like this: | Another way to prevent the GUI from being actioned while the ''MsgBox'' is present is to set the "''parent''" parameter like this: | ||
<syntaxhighlight lang="autoit"> | <syntaxhighlight lang="autoit"> | ||
#include <GUIConstantsEx.au3> | #include <GUIConstantsEx.au3> | ||
Line 79: | Line 75: | ||
WEnd | WEnd | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 13:19, 11 November 2012
Modal MsgBox Styles
MsgBox is a blocking function which means that a script pauses until a button on the MsgBox is pressed at which point the function terminates with a return value which you can use in a decision structure of some kind. Your main GUI appears unresponsive until the MsgBox is cleared. However, things are not quite that simple because the MsgBox can be set as Application, System or Task Modal. Although the values needed to set these styles are given in the Helpfile, it does not actually explain the difference between them.
Application
This is the default setting. In this case your GUI will react to mouse clicks and will even retake focus from the MsgBox, but will not act on the clicks until the MsgBox is cleared. Try closing the main GUI while the MsgBox is displayed - it will not close unless you clear the Msgbox first:
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 500, 500)
GUISetState()
MsgBox(0, "Blocking", "Press me to continue")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
System Modal
Now the MsgBox remains in view even if the main GUI regains focus although the main GUI appears inactive the GUI. However if the main GUI is closed this will again occur as soon as the MsgBox is cleared.
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 500, 500)
GUISetState()
MsgBox(4096, "Blocking", "Press me to continue")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Task Modal
Now we get to the real deal - you cannot action anything on the main GUI until the MsgBox is cleared. So you cannot close the main GUI - or do anything else with it at all!
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 500, 500)
GUISetState()
MsgBox(8192, "Blocking", "Press me to continue")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Now all you have to do is choose which type best suits your needs!
An Added Extra
Another way to prevent the GUI from being actioned while the MsgBox is present is to set the "parent" parameter like this:
#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 500, 500)
GUISetState()
MsgBox(0, "", "", 0, $hGUI)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd