Jump to content

Func WaitForAnyWin


jamesband
 Share

Recommended Posts

Func WaitForAnyWin( $zwingroup , $ztimeout )
    $zwinlist = StringSplit( $zwingroup , "," )
    $ztimer = TimerInit()
    While TimerDiff( $ztimer ) < ( $ztimeout * 1000 )
        For $x = 1 to $win[0]
            If WinExists( $zwinlist[$x] , "" ) then Return $x
        next
        Sleep( 100 )
    Wend
    Return -1
EndFunc

The above code is a little function I created to wait for any of several windows to open. I created this out of necessity, of course. So there it is and here is an example of how to call it:

$retvalue = WaitForAnyWin( "Notepad.exe,Internet Explorer,Paint" , 15 )

The above call cause the function to wait for up to 15 seconds for Notepad, Internet Explorer, or Paint to open. If one of the opens, then the number of it's place in the list is returned. If the function times out, then -1 is returned. So, lets say that Paint is opened within 15 seconds of the call. In this instance, a value of 3 (number) would be returned.

I hope it helps someone. I have found it very useful for intercepting error windows.

If you prefer to use milliseconds instead, just remove the '* 1000' from the 'While' line!

JamesBand :(

Link to comment
Share on other sites

congrats on your first script that you posted here. it looks nice.

impoved it a bit since there was an error w/ ur variables

made the timeout optional. (default is forever)

it now also returns an array

[0] = index number

[1] = search string

[2] = full title of the found window

Func WaitForAnyWin($s_zwingroup, $i_ztimeout = 0)
    
;declaring local vars
    Local $av_ret[3]
    Local $as_zwinlist = StringSplit($s_zwingroup, ",")
    Local $v_ztimer = TimerInit()
    
;infinite loop
    If $i_ztimeout = 0 Then
        While 1
            For $i_x = 1 To $as_zwinlist[0]
                If WinExists($as_zwinlist[$i_x]) Then
                    
               ;wrinting and returning the array
                    $av_ret[0] = $i_x
                    $av_ret[1] = $as_zwinlist[$i_x]
                    $av_ret[2] = WinGetTitle($as_zwinlist[$i_x])
                    Return $av_ret
                    
                EndIf
            Next
            Sleep(100)
        WEnd
    EndIf
    
;timeout loop
    While TimerDiff($v_ztimer) < $i_ztimeout
        For $i_x = 1 To $as_zwinlist[0]
            If WinExists($as_zwinlist[$i_x]) Then
                
           ;wrinting and returning the array
                $av_ret[0] = $i_x
                $av_ret[1] = $as_zwinlist[$i_x]
                $av_ret[2] = WinGetTitle($as_zwinlist[$i_x])
                Return $av_ret
                
            EndIf
        Next
        Sleep(100)
    WEnd

    Return -1
EndFunc ;==>WaitForAnyWin

; test peice
;$i = WaitForAnyWin("E:\")
;msgbox(0, '', $i[0] & @CRLF & $i[1] & @CRLF & $i[2])
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...