Sign in to follow this  
Followers 0
Mingre

Detecting newly-opened application window [RESOLVED]

1 post in this topic

#1 ·  Posted (edited)

I'd like to include in my script a part which will inform me via MsgBox() whenever a visible application window has just been opened.

I'm thinking of using WinList() function prior the execution of an application and then using another Winlist() function after the window has opened. Is this feasible? If it is, please help 'cause I can't think of how to compare the arrays produced by two WinList() function.

$before = WinList()


AdlibRegister("New", 1000)

Func New()
    $after = Winlist()
    If $before = $after Then
        TrayTip("","No change.", 5)
    Elseif $before <> $after Then
        TrayTip("","Arrays - not equal", 5)
        $before = WinList()
    EndIf
EndFunc

Sleep (50000)

Result = always "not equal" even if I didn't open anything.

Second crappy code tried:

#include <Array.au3>
Global $x[50]

$var = WinList()
$count = 1
For $i = 1 to $var[0][0]
  ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    $x[$count] = $var[$i][1]
    $count = $count + 1
    
  EndIf
Next

$a = $x
_ArrayToClip($a)
MsgBox(0, "_ArrayToClip() Test", ClipGet()) ; DISPLAY THE CONTENTS OF THE FIRST ARRAY

Compare()
Hotkeyset("{ESC}","Compare")

Func Compare()
    $count = 1
    For $i = 1 to $var[0][0]
      ; Only display visble windows that have a title
      If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
        $x[$count] = $var[$i][1]
        $count = $count + 1
        ;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]  & @LF & $i)
      EndIf
  Next

_ArrayToClip($x)
MsgBox(0, "_ArrayToClip() Test", ClipGet()) ; DISPLAY THE SECOND ARRAY

    If $x = $a Then
        MsgBox(0,"","No change.")
    Else
        msgbox(0,"","Not Equal.")
    EndIf
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Problems:

1. Even if the contents of the two arrays displayed are equal, I still get "Not equal" as a result when comparing them.

2. The index of my array on the declaration is greater than what I need.

Thanks!

L. Go

(Please correct me if I'm using a term or two incorrectly. It's a tendency.)

Edit: The two trial-scripts were added. Please bear with their being ugly.

Edited by Lilbert

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