Jump to content

Inconsistent WinList results


Recommended Posts

I wanted to develop a testing script that used WinList to determine if any unexpected windows existed, however I am having some trouble.

I get very inconsistent results from WinList. I have the same items open for every test; SciTE, Outlook, IE, AutoIt Help.

I am using two filters on the results from WinList, Windows Title <> "" and WinGetState > 5. Sometimes it just will not pick up AutoIt Help for example (though it would detect the rest), but it I just run it again, it sometimes will. If it isn't picking it up, and I use a separate scriptlet to WinGetState on AutoIt Help specifically, then it always works.

It tried working without the filters too, just to see if they were the issue, but once again, sometimes some of the windows were just not returned.

Here is the latest test code I have been running (Beta).

#include <Array.au3>
If FileExists(@WorkingDir&"\WinList.txt") Then
    FileDelete(@WorkingDir&"\WinList.txt")
EndIf

$oFSO = ObjCreate("Scripting.FileSystemObject") 
$LogFile = $oFSO.OpenTextFile(@WorkingDir&"\WinList.txt",8,true)

$List = WinList()
$Top = UBound($List,1)-1

For $item = 1 To $Top
    $Value = $List[$item][0]
    $Value2 = $List[$item][1]
    $State = WinGetState($Value2)

If $State > 5 And $Value <> "" Then
;$LogFile.WriteLine ($List[$item][0]&"  "&$State)
;$LogFile.WriteLine ("")
    MsgBox(0,"",$Value)
ElseIf $Value = "AutoIt Help" Then
    MsgBox(0,"","Not displayed: "&$Value&"   "&$State)
EndIf

    $item = $item+1
    $Value = ""
Next
$LogFile.Close

Any thoughts?

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Link to comment
Share on other sites

Why use this:

$item = $item+1

inside a For/Next:

For $item = 1 To $Top

...and do you need to BitAnd your check on $State...

The $item was just making sure it was iterating properly; the code is a work in progress, and is by no means streamlined.

BitAnd or not, even removing the filter WinGetState entirely, It does not return all the windows every time it runs.

If you try:

#include <Array.au3>


$List = WinList()
$Top = UBound($List,1)-1

For $item = 1 To $Top
    $Value = $List[$item][0]

If $Value <> "" Then
    MsgBox(0,"",$Value)
EndIf


    $Value = ""
Next

Sometime all the windows return, sometimes not.

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Link to comment
Share on other sites

The $item was just making sure it was iterating properly; the code is a work in progress, and is by no means streamlined...

Incrementing $item within the For/Next loop meant that you were only processing every other window... I thought that this could be the cause of your problem. If the Z order changed, the AutoIt window would be skipped sometimes.

I don't see any problems when I run:

$List = WinList()

For $item = 1 To ($List[0][0]-1)
    $Value = $List[$item][0]
    
    If $Value <> "" Then
        MsgBox(0, "", $Value)
    EndIf
Next
What do you see?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

If you run this within SciTE - you should see the numbers change.

$List1 = WinList()
Sleep(300)
$List2 = WinList()
Sleep(300)
$List3 = WinList()

MsgBox(0, "Compare", $List1[0][0] & @CR _
         & $List2[0][0] & @CR _
         & $List3[0][0] & @CR)
...but outside of SciTE, all 3 match.

Edit: or am I not understanding the problem???

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

If you run this within SciTE - you should see the numbers change.

$List1 = WinList()
Sleep(300)
$List2 = WinList()
Sleep(300)
$List3 = WinList()

MsgBox(0, "Compare", $List1[0][0] & @CR _
         & $List2[0][0] & @CR _
         & $List3[0][0] & @CR)
...but outside of SciTE, all 3 match.

Edit: or am I not understanding the problem???

A second instance of AutoIt3Wrapper starts after your 1st WinList() read, so that is why you get change when running in Scite. Add a Sleep(500) to the start of the script and you will see same results with or without Scite. :D

Edit:

Ravenlark, I notice that you are not using BitAnd() on $State after it was returned from WinGetState(). This may affect your results.

Edited by MHz
Link to comment
Share on other sites

Incrementing $item within the For/Next loop meant that you were only processing every other window... I thought that this could be the cause of your problem. If the Z order changed, the AutoIt window would be skipped sometimes.

I don't see any problems when I run:

$List = WinList()

For $item = 1 To ($List[0][0]-1)
    $Value = $List[$item][0]
    
    If $Value <> "" Then
        MsgBox(0, "", $Value)
    EndIf
Next
What do you see?
Sorry it took me a while to post back (meetings).

Your totally right. I feel like an UltraNewbie. I ran some more tests and it look like my stupid $item=$item+1 was causing it to skip windows.

Thanks for the wakeup call; this is what I get for trying to code in the middle of the night. :D

Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain

Link to comment
Share on other sites

A second instance of AutoIt3Wrapper starts after your 1st WinList() read, so that is why you get change when running in Scite. Add a Sleep(500) to the start of the script and you will see same results with or without Scite. :D...

Interesting that you should mention Sleep(500) at the start of the script... I actually added that very sleep value as the first line after seeing that second AutoIt3Wrapper via PrcView*, but I removed that line for the post to show that windows come and go and to highlight that testing code like this within SciTE (and company) might have "interesting results".

Thanks for the confirmation :-)

*...but it took several runs of the code to catch the event - I should have used ConsoleWrite or the like to compare the delta...

[size="1"][font="Arial"].[u].[/u][/font][/size]

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