Problem automating Notepad
Keywords: Problem Notepad cClickButton multiple windows same name
Question:
I am running through control manager tutorial. I attempted to add code
that clicks the 'Save As' button. All was fine on the first run. When you
attempt to run the code again, Notepad prompts you with a dialog, asking if
your sure your want to overwrite, with a Yes and No button. This dialog has
the same name ('Save As') as the other window.......
How can I differentiate between the two windows???????
Answer:
Here is some sample code that may help.....
AddExtender("wwctl34I.dll")
;get process id of launched instance......
procid=Runshell("notepad.exe","","",@normal,@GETPROCID)
SendMenusTo("~Notepad","FileSaveAs")
WinWaitExist("Save As",5)
parentHwnd=DllHwnd("Save As")
editHwnd=cWndByID(parentHwnd,1152)
cSetEditText(editHwnd, "C:\Windows\Desktop\Test.txt")
saveasbutton=cWndByID(parentHwnd,1)
;Use 'other' method of pressing a button
cpostbutton(saveasbutton)
timedelay(1)
;Get a list of window ids associated with the process
list=WinitemProcid(procid,4,0)
count=ItemCount(list,@tab)
if count==3; found the 'save as overwrite' dialog
confirmwin=ItemExtract(1,list,@tab)
phwnd=DllHwnd(confirmwin)
yesbutton=cWndByID(phwnd,6)
cclickbutton(yesbutton)
endif
Exit
Article ID: W14524
Filename: Problem automating Notepad.txt