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.

WinWaitListExist UDF

Keywords: 

Question:

I have an interesting problem to solve... 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. Right now, I'm just using some code that calls WinExist() in a loop and checks for all possible windows that I might expect to pop up. However, I'd like to request that an enhanced form of WinWaitExist() be developed so that I can pass in a delimited list of partial window names along with a timeout period. Then, when any one of those windows is displayed, the return value of the function would indicate the item # in the delimited list so that I would know which window was displayed. If the timeout period elapses w/o any of the windows being displayed, then the function could return zero [@FALSE] as is done now by WinWaitExist(). Does this sound like a reasonable enhancement request?

Answer:

Here's a UDF I threw together in a couple of secs.. hopefully you will find it of use (if you haven't already done it yourself).
#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:   W15744
File Created: 2003:05:13:11:29:54
Last Updated: 2003:05:13:11:29:54