legend Posted October 6, 2012 Share Posted October 6, 2012 Hi, can I use winwaitactive for more windows? so if some window appears it opens mspaint, and if some other window is detected, it also opens mspaint, I tried the code i posted here, but it doesen't work, since it waits for the first window (Notepad) Opt("WinTitleMatchMode", 2) func test1() ShellExecute("mspaint.exe") EndFunc WinWaitActive("Notepad") Call("test1") WinWaitActive("Test") Call("test1") MrGunders 1 Link to comment Share on other sites More sharing options...
nitekram Posted October 6, 2012 Share Posted October 6, 2012 I do not think it is possible with that function, as it will pause the script until it sees the window. You might be able to use ProcessExists() and put it in a while loop and it may work? 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
water Posted October 6, 2012 Share Posted October 6, 2012 (edited) Use $sWindowTitle = WinGetTitle("[ACTIVE]")to get the title of the active window and check the title for what yo need in a loop (don't forget the Sleep). Edited October 6, 2012 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
FireFox Posted October 6, 2012 Share Posted October 6, 2012 (edited) Hi, Maybe this? Opt("WinTitleMatchMode", 2) Local $aWaitActiveWnd[2] = ["Notepad", "Test"] _WinWaitActiveMultiple($aWaitActiveWnd) test1() Func test1() ShellExecute("mspaint.exe") EndFunc ;==>test1 Func _WinWaitActiveMultiple($aWnd, $iTimeOut = 0) If $iTimeOut > 0 Then Local $iTimer = TimerInit() EndIf While 1 For $iWnd = 0 To UBound($aWnd) - 1 If WinActive($aWnd[$iWnd]) Then Return $iWnd Next If $iTimeOut > 0 Then If TimerDiff($iTimer) >= $iTimeOut * 1000 Then ExitLoop EndIf Sleep(50) WEnd EndFunc ;==>_WinWaitActiveMultiple Br, FireFox. Edited October 6, 2012 by FireFox Link to comment Share on other sites More sharing options...
legend Posted October 6, 2012 Author Share Posted October 6, 2012 hi firefox works pretty good, but if you then open notepad, and it then opens mspaint, then you open some other window, and open notepad again, then it does not open mspaint, is it possible to do that ? Link to comment Share on other sites More sharing options...
FireFox Posted October 6, 2012 Share Posted October 6, 2012 (edited) @legend Of course it is : ... While 1 _WinWaitActiveMultiple($aWaitActiveWnd) test1() WEnd ... Br, FireFox. Edited October 6, 2012 by FireFox Link to comment Share on other sites More sharing options...
wolf9228 Posted October 6, 2012 Share Posted October 6, 2012 (edited) Hi, can I use winwaitactive for more windows? so if some window appears it opens mspaint, and if some other window is detected, it also opens mspaint, I tried the code i posted here, but it doesen't work, since it waits for the first window (Notepad) Opt("WinTitleMatchMode", 2) func test1() ShellExecute("mspaint.exe") EndFunc WinWaitActive("Notepad") Call("test1") WinWaitActive("Test") Call("test1") expandcollapse popupGlobal $ActiveArray = 0 HotKeySet("{ESC}", "Terminate") ShellExecute("notepad.exe","",@SystemDir,"",@SW_MINIMIZE) ShellExecute("mspaint.exe","",@SystemDir,"",@SW_MINIMIZE) ShellExecute("wordpad.exe","",@SystemDir,"",@SW_MINIMIZE) RegisterWindows("Untitled - Notepad","","CallbackFunc") RegisterWindows("Untitled - Paint","","CallbackFunc") RegisterWindows("Document - WordPad","","CallbackFunc") While True Sleep(100) WEnd Func CallbackFunc($Winhandle,$Title,$Text) MsgBox(0,"Active","Winhandle Is " & $Winhandle & @CRLF & _ "Title Is " & $Title & @CRLF & "Text Is " & $Text) EndFunc Func WindowsIsActive() if IsArray($ActiveArray) Then For $i = 0 To (UBound($ActiveArray) - 1) $Winhandle = WinActive($ActiveArray[$i][0],$ActiveArray[$i][1]) if ($Winhandle) Then Call($ActiveArray[$i][2],$Winhandle,$ActiveArray[$i][0],$ActiveArray[$i][1]) RegisterWindows($ActiveArray[$i][0],$ActiveArray[$i][1],$ActiveArray[$i][2],2) ;UnRegister ExitLoop EndIf Next EndIf EndFunc Func RegisterWindows($Title,$Text,$CallbackFunc,$Flag = 1) ;$Flag = 1 Register ;$Flag = 2 UnRegister Switch $Flag Case 1 AdlibRegister("WindowsIsActive") if Not IsArray($ActiveArray) Then Local $TempActiveArray[1][3] $TempActiveArray[0][0] = $Title $TempActiveArray[0][1] = $Text $TempActiveArray[0][2] = $CallbackFunc $ActiveArray = $TempActiveArray Return SetError(0,0,True) Else For $i = 0 To UBound($ActiveArray) - 1 if $Title == $ActiveArray[$i][0] And $Text == $TempActiveArray[0][1] _ And $CallbackFunc == $TempActiveArray[0][2] Then Return SetError(1,0,False) Next ReDim $ActiveArray[UBound($ActiveArray) + 1][3] $ActiveArray[UBound($ActiveArray) - 1][0] = $Title $ActiveArray[UBound($ActiveArray) - 1][1] = $Text $ActiveArray[UBound($ActiveArray) - 1][2] = $CallbackFunc Return SetError(0,0,True) EndIf Case 2 if IsArray($ActiveArray) Then Local $TempActiveArray[UBound($ActiveArray)][3],$Test = False , $j = 0 For $i = 0 To UBound($ActiveArray) - 1 if $Title == $ActiveArray[$i][0] And $Text == $ActiveArray[0][1] _ And $CallbackFunc == $ActiveArray[0][2] Then $Test = True ContinueLoop EndIf $TempActiveArray[$j][0] = $ActiveArray[$i][0] $TempActiveArray[$j][1] = $ActiveArray[$i][1] $TempActiveArray[$j][2] = $ActiveArray[$i][2] $j += 1 Next if ($Test) Then if UBound($TempActiveArray) > 1 Then ReDim $TempActiveArray[UBound($TempActiveArray) - 1][3] $ActiveArray = $TempActiveArray Else $ActiveArray = 0 AdlibUnRegister("WindowsIsActive") EndIf Return SetError(0,0,True) Else Return SetError(2,0,False) EndIf EndIf Case Else Return SetError(3,0,False) EndSwitch EndFunc Func Terminate() Exit 0 EndFunc Edited October 6, 2012 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now