WinWaitExist

Started by jkjk12, September 16, 2015, 10:08:29 AM

Previous topic - Next topic

jkjk12

How do I use a WHILE statement to wait for a window to exist?

RunHide("\\server\share\ProgramToRun.exe","")
While WinWaitExist == (@FALSE, 2)
EndWhile
Message("OK", "Now we see the window")


OR

RunHide("\\server\share\ProgramToRun.exe","")
While WinWaitExist == @FALSE (~Alaris, 3)
EndWhile
Message("OK", "Now we see the window")

Both fail.

Thank you. 

td

I would hope they both failed.  There are numerous ways to use WinWaitExist in a while loop.   It depends on your intentions.  But first you may want to review your the function's syntax in the Consolidated WIL Help file.  You may not need to use it in a loop.

Here is a simple example of using the function in a loop:
Code (winbatch) Select

Run("Notepad.exe", "")

while 1
   if WinWaitExist("~Notepad", 1) then break
   Pause("Notepad", "Still waiting")
endwhile


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

Note, incidentally, that if you do just want to wait "forever" (which is the effect of the WHILE loop), then you can just pass -1 as the "how long to wait" parameter, like this:

; No WHILE loop at all
WinWaitExist("winnamegoeshere",-1)
Pause("It is","there!")

td

At the risk of splitting a hair or two unnecessarily, a while loop obviously does not necessarily cause waiting forever. For example, pressing the 'Cancel' button on the Pause function's message display in the above loop would cause loop exit without the application window being found. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

Quote from: td on September 17, 2015, 07:36:03 AM
At the risk of splitting a hair or two unnecessarily, a while loop obviously does not necessarily cause waiting forever. For example, pressing the 'Cancel' button on the Pause function's message display in the above loop would cause loop exit without the application window being found.

I was actually addressing the OP.  And in his loop, there was no Pause() statement.

Clearly, when you added in the Pause() statement, then it was no longer a simple "Wait forever until the window appears" loop.

One might also infer that in the OP's actual application, there was some reason for coding it as a WHILE loop - that in the actual program, the loop is not empty.

td

Given the nature of the original post in this topic, a qualifying explanation seemed appropriate to avoid misunderstanding.   And, yes, the -1 option should have been explicitly mentioned in the first reply. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

DAG_P6

From time to time, I have coded similar wait loops into scripts. I always put a Yield statement in the loop, to relinquish the processor so that other message pumps get a chance to process their messages.
David A. Gray
You are more important than any technology.