Home > Language Reference > Windows Management Functions > ExistW

ExistW

The ExistW function checks if the specified window exists or not.

Usage

Used to test if a window appearing only in some circumstances is there or not, and then click a button in it if the window is displayed.  

Syntax

ret=ExistW(<window_name>)

Parameters

<window_name>, string, window name  of the window to check. You can truncate <window_name> to check a window whose title starts with the specified characters.

Return value

ret, numeric return value. The function returns 1 if <window_name> exists, it returns 0 if not.

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 script execution.

See also

CheckedW

Examples

a = ExistW("NOTEPAD.EXE|Edit|Untitled")

'If within a script, you save a file, next time you replay the script, a new window prompts for replacing the file.
'ExistW function is used in this example in order to replay correctly the script if the file already exists or not.
'launch notepad
Shell("notepad",1)
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
'Type some text
SendKeys("Hello")
'Close notepad
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
'Click Save when prompted
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Notepad|7",1)
 Click(Button,"&Save")
'Type a filename for saving the file, type the name including the full path
UseWindow("NOTEPAD.EXE|FloatNotifySink|Save As|1",1)
 WriteCombo("1","c:\wttest\existw.txt")
'Click Save button
UseWindow("NOTEPAD.EXE|#32770|Save As",1)
 Click(Button,"&Save")
'If the file already exists, an additional window is displayed, test if it is there, if yes, click Yes button to replace the existing file
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)