WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Windows UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDF - WinWaitListExist

This UDF will wait for any of a list of windows to show up. Similar to WinWaitExist, but with multiple target windows.
#DefineFunction WinWaitListExist(List, Timeout, Delimiter)

   NumOfElements = ItemCount(List, Delimiter)
   TimeAtInit=TimeYmdHms( )
   
   While @TRUE
      For i=1 To NumOfElements
         CurrentWin = ItemExtract(i, List, Delimiter)
         If WinExist(CurrentWin) Then Return i ;returns item number in delimited list
      Next
      If Timeout >= 0 ;Assume Negative Timeout means 'wait forever'
         TimeNow = TimeYmdHms()
         TimePassed=TimeDiffSecs(TimeNow, TimeAtInit)
         If TimePassed > Timeout Then Return @FALSE
      EndIf
      TimeDelay(1) ;Sleep for one second the check windows again
   EndWhile

#EndFunction


;---------------------------------------------
;Test Program

Timeout = 3
Delimiter = @TAB
List = StrCat("Some App", @TAB, "Untitled - Notepad", @TAB, "Some Other App")

;run without notepad being opened 
result = WInWaitListExist(List, Timeout, Delimiter)
Message("Result", result)

;now open Notepad
Run("notepad.exe", "")
result = WInWaitListExist(List, Timeout, Delimiter)
Message("Result", result)

;-------------------------------------------------------

Article ID:   W16238
File Created: 2004:03:30:15:43:32
Last Updated: 2004:03:30:15:43:32