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.

Wait on Multiple Windows


Question:

I'm automating the startup of an application with a WinBatch script. This application may enounter some situations when starting up that will cause it to display one or more message boxes that need to be cleared out before the application startup is complete and the app's main window is displayed. I want to detect when any of these windows appears while waiting for the main app window to appear.

Answer:

Here's a UDF that you will hopefully find of use.
;WINWAITLISTEXIST.WBT (1KB) 
;Make WinWaitEixst use delimited lists 

#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


;---------------------------------------------
;Main 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:   W16241
File Created: 2004:03:30:15:43:32
Last Updated: 2004:03:30:15:43:32