Jump to content
Macro Express Forums

Self-closing Dialog Box


Recommended Posts

It's sometimes useful to be able to display a pause dialog box which closes itself after some number of seconds.

 

I have a need for this capability, and wish to take one of two actions, depending on whether the dialog box is closed by the macro after the specified timeout, or manually by the user. I've developed a series of macros and other utilities which I want to run in two different ways:

  • when testing, I need to inspect the results produced in the previous step before continuing
  • when running unattended in a production environment, I need the process to run from beginning to end without the need for user intervention

Here is the code for a macro that accomplishes this. Please note that this implementation of the macro uses two functions from our PGM Library to capture the current time to the nearest millisecond, so if you don't have this library you need to recreate their functionality.

<REM2:This macro displays a Pause dialog box that closes itself after><REM2:the number of seconds specified in N91, and then checks to see><REM2:how the dialog box was closed (i.e. automatically because of a timeout,><REM2:or manually because of user intervention).><REM2:If the close was automatic, the macro continues, otherwise it waits><REM2:for a specific key press (in this example, the Esc key) before continuing.><REM2:><REM2:This implementation uses the PGM Library functions><REM2:   { Utility - Start Timer }     and><REM2:   { Utility - Get Timer }><REM2:to set and return the elapse time in milliseconds.><REM2:><REM2:Local variables -><REM2:T1, T2, N1 = Temporary variables><REM2:T91 = Pause message to display><REM2:N91 = Number of seconds to wait before a timeout occurs><REM2:____________________________________________________________________________
________________><REM2:><REM2:Timeout number of seconds><IVAR2:91:01:8><REM2:><REM2:PGM Library Function><MACRUN2:{ Utility - Start Timer }><REM2:><REM2:Display Pause dialog box for N91 seconds><TBOX4:T:2:CenterCenter000300000200:%N91%:Pausing (closes after %N91% seconds)%T91%><REM2:><REM2:Check to see if Pause dialog box window is still open><REP3:08:000002:000002:0001:1:01:N1><IFOTH:12:2:Pausing><BREAK><ENDIF><ENDREP><REM2:><REM2:PGM Library Function><MACRUN2:{ Utility - Get Timer }><REGRSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ReturnString1><REM2:><REM2:Derive number of seconds the Pause dialog box was open><IVAR2:01:13:1::><TMVAR2:11:01:00:001:N01:><IVAR2:01:13:1::><TMVAR2:11:01:00:001:N01:><TMVAR2:05:01:01:000:000:><REM2:><IFVAR2:5:01:5:N91><REM2:Automatically closed after timeout, therefore continue with macro><TBOX4:T:2:CenterCenter000300000200:005:Elapse Time (closing after 5 seconds)Dialog box closed itself after %N1% seconds

Continuing on with macro><DELAY:5><ELSE><REM2:Manually closed by the user, therefore wait for the Esc key before continuing><TBOX4:T:2:CenterCenter000300000200:005:Elapse Time (closing after 5 seconds)Dialog box was closed manually after only %N1% seconds

Waiting for the Esc key to be pressed before continuing><DELAY:5><WAITKEY2:000000:000000:48><ENDIF><REM2:><REM2:Continue on with macro><TBOX4:T:1:CenterCenter000300000200:000:ContinuingMacro continues>

In itself, this macro does nothing useful. But it can easily be modified to provide quite useful functionality, by replacing the informational messages with other code.

 

You can also address its use of variables by doing Variable Save/Restore commands at suitable points.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...