Macro Scheduler 15

Modal vs Non-Modal Dialogs


 

Modal Windows

 

When a window is modal it remains active and focused until the user has finished with it and dismisses it.  While it is active no other windows of the same application can be activated.  A modal window is therefore normally a child window.  The user needs to interact with it before control can be returned to the parent application. In effect the parent application is locked and nothing proceeds until the modal window is closed.

 

You?ll find a good definition of Modal Windows on Wikipedia, here:

http://en.wikipedia.org/wiki/Modal_window

 

Non-Modal Windows

 

So a non-modal window is the opposite. While it is active you can still activate other windows. The user can switch between windows of the same application. The window being active does not prevent the rest of the application from continuing.

 

Modal Dialogs

 

In Macro Scheduler you can create custom dialogs. These can be modal or non-modal to the script. When we refer to a modal dialog what we mean is that once the dialog is displayed, the main script code halts until the user closes the dialog. With the exception of subroutines linked to dialog events with AddDialogHandler, script execution is paused until the dialog is dismissed. The script cannot do any other processing while the modal dialog is active. A modal dialog is displayed with the Show command, with a return variable specified, in which the ?modal result? of the dialog is reported, corresponding to which button was pressed to close the dialog.  E.g.:

 

Show>MyDialog,result

If>result=10

 MessageModal>You clicked the OK button

Endif

 

In the above example a dialog was shown modally, because a result variable was specified in the Show command.  A button whose modal result was set to 10 was clicked, setting the result of the Show command to that value.

 

In order to use modal dialogs you need to set the "ModalResult" property of any button that should close the dialog (e.g. OK and Cancel buttons), and provide a return variable in the Show function.  When a button is pressed, the dialog is closed and the Show command returns the button's ModalResult value.

 

Note that if a button's ModalResult value is zero (the default) it will not close the dialog.  To respond to button clicks for buttons that should not close the dialog, leave ModalResult for those buttons to zero and create an event handler with the AddDialogHandler command.

 

Most dialogs would be modal, as in most cases you will want to pause execution of the script while the dialog is visible.

 

A note for existing users:  If you are coming from Macro Scheduler prior to version 12 you will find you no longer need to make your dialog non-modal in order to interact with it and modify its properties, as all event handlers are now executed instantly, whether or not the dialog is modal.  Prior to v12 the most common reason for making a dialog non-modal was so that you could detect changes on it and update it due to the fact that scripts were executed sequentially. AddDialogHandler creates real time event code that can be executed at the same time as other code and even when the dialog is modal.  Therefore in most cases you should find you no longer need non-modal dialogs.

 

So, to recap, when using Show>dialogname,result the code after the Show command does not get executed until the dialog has been closed.  The exception to this is any event handler code in subroutines used by AddDialogHandler for the dialog concerned.

 

Non-Modal Dialogs

 

A dialog can be made to be non-modal. In which case the script carries on even after it has displayed the dialog. The user can interact with the dialog while the script continues to perform other tasks.

 

To display a dialog non-modally specify the Show function without a result variable.  E.g.:

 

Show>MyDialog

 

Since a non-modal dialog does not halt execution of the script, your script will usually need to be doing something - if there is no code after the Show command, your script will end and you will barely have time to see the dialog appear and then disappear before blinking!   Any code after the Show command will be executed immediately - as soon as the dialog is made visible.

 

A non-modal dialog would be useful to display progress during a long or looping script, or where you have more than one dialog that need to interact with each other.