ExistW
Windows management function.
The ExistW function checks for the existence of the specified window.
Usage
If a window appears only in some circumstances, you can test if it is there using ExistW function. For example, when you save a document, depending if the document already exists or not, you get or you do not get a window prompting to replace it.
Syntax
ret=ExistW(<window_name>[,<instance>])
Parameters
<window_name>, window name of the window to test.
<instance>, optional, instance number of the window.
Return value
ret, numeric return code ; if the window exists and is displayed, the return code is set to 1, otherwise 0.
Remarks
To know if a script (.rob) is running, use
ExistW("TASKEXEC.EXE|TaskExec|my_script.rob",1)
which returns 1 if the script's icon exists (this does not work if #HideIcon = 1).ExistW function used in conjunction with an If structure can be used for testing if a window appears during a task.
ExistW never truncates the specified window name, so if you want to check the existence of a window which title changes at replay, truncate its window name.
See also
CheckedW for interaction with ExistW in case of a check box or a radio button.
Examples
a = ExistW("NOTEPAD.EXE|Edit|Untitled")
a = ExistW("NOTEPAD.EXE|Edit|Untitled",1)
'Click Yes button for replacing a document if it already exists
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
SendKeys("Hello")
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
UseWindow("NOTEPAD.EXE|#32770|Notepad",1)
Click(Button,"&Yes")
UseWindow("NOTEPAD.EXE|SHELLDLL_DefView|Save As|1",1)
ChooseItem(ListView, "1", "test.txt", single, left )
UseWindow("NOTEPAD.EXE|#32770|Save As",1)
Click(Button,"&Save")
If ExistW("NOTEPAD.EXE|#32770|Save As") = 1 then
Click(Button,"&Yes")
Endif
ExistW function can be used to write a Function which waits for one window to appear OR a second window to appear:
function wait_for_two_window(name1$,name2$, Timeout)
'The function returns 0 if none of the 2 specified window names have been found within timeout
local ret, t
repeat
ret=existw(name1$)
if ret=0 then
ret=existw(name2$)
if ret=0 then
pause 1
t=t+1
else
ret=2
endif
endif
until ret > 0 or t > timeout
wait_for_two_window=ret
EndFunction
'CALL example
res=wait_for_two_window("NOTEPAD.EXE|Notepad|","CALC.EXE|#32770|Calc", 10)
msgbox(res)