WaitWindowFocused


 

WaitWindowFocused>window_title

 

Waits for a specified window to open/appear and be focused (the foreground window).  Execution of the script will not continue until a window with the specified title text appears and is focused or a specified timeout value is exceeded.  The window title may contain the * symbol at the end to indicate a substring match.

 

If the WIN_USEHANDLE variable is set to 1 window_title must be a window handle.

 

If the last character of the window title specified is an asterisk (*), Macro Scheduler will first attempt to find the first window whose title matches the text entered exactly. If it cannot make an exact match it then looks at all windows and selects the first one it finds whose title contains the entered text (using a case-insensitive search). This solves the problem with applications such as Word or Netscape which change their titles depending on the document loaded. It is best to try to provide an exact (including case) window title to ensure the correct window is found, as many applications have multiple invisible windows with similar names.  Specifying text without a trailing asterisk will force Macro Scheduler to only look for an exact match.

 

The system variable WW_TIMEOUT can be used to set the number of seconds after which this command should timeout.  If set to zero (the default) the timeout will not occur and the command will continue indefinitely.  If WW_TIMEOUT is used, WW_RESULT will indicate whether or not the command ended successfully.  If it timed out WW_RESULT will be set to FALSE.  If the window it was waiting for appeared within the timeout setting, the WW_RESULT value will be set to TRUE.

 

It is possible to limit the type of windows this command affects using the WF_TYPE variable:

 Let>WF_TYPE=0 - No Child Windows

 Let>WF_TYPE=1 - ALL Windows (Default)

 Let>WF_TYPE=2 - Visible Windows Only

 Let>WF_TYPE=3 - Child Windows Only

 

A Regular Expression can be used in window_title if WIN_REGEX is set to 1.

 

By definition this function continually enumerates and loops through the list of windows open on the system. This is an intensive process and you may therefore see CPU usage increase during the wait.  For most people this is not a problem. However, if you wish to reduce CPU usage you can set WIN_SLEEP to 1 at the expense of processing time (in theory setting WIN_SLEEP to 1 will slow the function down while reducing CPU usage).

 

Abbreviation : WWF

See also: Wait, WaitWindowOpen, WaitWindowClosed, WaitWindowChanged

 

Examples

 

Run Program>c:\program files\msoffice\winword.exe

WaitWindowFocused>microsoft word*

 

//With timeout checking

Let>WW_TIMEOUT=30

WaitWindowFocused>microsoft word*

If>WW_RESULT=FALSE

  MessageModal>Error starting Word!

Endif