Jump to content

winwaitactive for more than one?


 Share

Recommended Posts

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")
Link to comment
Share on other sites

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?

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."

 

WindowsError.gif

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

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 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

Hi,

Maybe this? :huh:

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 by FireFox
Link to comment
Share on other sites

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")

Global $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 by wolf9228

صرح السماء كان هنا

 

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...