<variable> = FOCUSCLASS(<"Window Class Name">,<Timeout in Seconds>, [option])
FOCUSCLASS is similar to FOCUS. FOCUSCLASS waits for the window with <Window Class Name> to appear within the specified amount of time and then set the focus to it. Certain windows may not contain a window title for FOCUS to focus on. This is where you use FOCUSCLASS. Every window has a class name. The class name is not visible to the user. Therefore, you may need to use a developer tool such as SPY++ to find out the window class name. When FOCUSCLASS finds the matching window, this window becomes the current destination window. Therefore, subsequence SEND or SYSCMD commands will be directed to this window. It's important that you set the focus to every popup window that may need to be automated even if the window is a simple open file dialog.
Example:
'-- Change the focus to "Untitled - Notepad"
IF FOCUSCLASS("Untitled - Notepad", 5, 1) = 0 THEN
'-- If never appears within the time then report error
PROMPT "Cannot Find Notepad", 5
ELSE
SEND "Hello, World!!! "
'-- Select File | New
SEND "@fn"
'-- see if notepad popup save changes dialog
'-- if so WAITWIN will set the focus to it
IF WAITWIN("Notepad", "&Yes", 2) = 1 THEN
'-- Send N for Not to save
SEND "N"
ENDIF
ENDIF
Parameters:
<Window Class Name > the class name to look for (case insensitive).
<Time in Seconds> specifies how long to wait. If the window does not appears within the specified time then FOCUS returns 0, otherwise, it returns 1.
<option> optional parameter which determines how FOCUSCLASS finds the window. If you leave this option out, Shortcut defaults to value to 1.
1 = Left-most part of the title must match <Window Title>
2 = Any part of the title that matches <Window Title>
Returns:
0 = if it cannot find any matching window within the specified amount of time
1 = if it finds the matching window.
Example #1:
'-- Change the focus to "Untitled - Notepad"
x = FOCUS("Untitled - Notepad", 10, 1)
'-- If the window never appears within the time then
'-- report error
IF x = 0 THEN
PRINT "Time Out Error"
ELSE
SEND "Hello Notepad."
ENDIF
Example #2:
'-- Change the focus to "Untitled - Notepad"
'-- If the window never appears within the time then
'-- report error
IF FOCUS("Untitled - Notepad", 10, 1) = 0 THEN
PRINT "Time Out Error"
ELSE
SEND "Hello Notepad."
ENDIF
See Also