Jump to content
Sign in to follow this  
legend

winwaitactive for more than one?

Recommended Posts

legend

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")
  • Like 1

Share this post


Link to post
Share on other sites
nitekram

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
FireFox

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
legend

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 :)?

Share this post


Link to post
Share on other sites
FireFox

@legend

Of course it is :

...

While 1

_WinWaitActiveMultiple($aWaitActiveWnd)

test1()
WEnd

...

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
wolf9228

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

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

 

Share this post


Link to post
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
Sign in to follow this  

×