Jump to content
Sign in to follow this  
Rota

Any Better way to Detect Window status

Recommended Posts

Rota

Hi Dears,

I am getting whacked on working with the windows status, take an example here:

When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window...

I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow...

Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces...

Thanks a ton

Regards

Share this post


Link to post
Share on other sites
picea892

Hi Dears,

I am getting whacked on working with the windows status, take an example here:

When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window...

I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow...

Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces...

Thanks a ton

Regards

Hi,

I think you may need to go to the next level if you are getting these types of problems. I used to use a WMI event notifiy. I only have examples in VBS so maybe someone can come along and provide an autoit example. The below link is close and could be tweaked to meet your needs

http://www.autoitscript.com/forum/index.php?showtopic=42580

Edited by picea892

Share this post


Link to post
Share on other sites
Yashied

Hi Dears,

I am getting whacked on working with the windows status, take an example here:

When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window...

I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow...

Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces...

Thanks a ton

Regards

What's wrong with WinWaitActive()? Edited by Yashied

Share this post


Link to post
Share on other sites
syno

Hi

I use an IF, THEN structure to only execute the next command once a window is active. This for me is the best resolution if you can see the window and it means you do not need to relay on the speed of your environment in order to execute you key strokes in sequence.

The code:

WinWait("User Sign-In", "")
If Not WinActive("User Sign-In", "") Then WinActivate("User Sign-In", "")
WinWaitActive("User Sign-In", "")
Send("{enter}")

Thanks

Edited by syno

Share this post


Link to post
Share on other sites
Rota

What's wrong with WinWaitActive()?

The problem is which window am I going to to WinWaiActive, cause when you click to the button, there could be 3 or even more windows pop-up... if I WinWaitActive(^_^, it will get hanged if B won't pop-up but C comes up...

Share this post


Link to post
Share on other sites
Rota

Hi

I use an IF, THEN structure to only execute the next command once a window is active. This for me is the best resolution if you can see the window and it means you do not need to relay on the speed of your environment in order to execute you key strokes in sequence.

The code:

WinWait("User Sign-In", "")
If Not WinActive("User Sign-In", "") Then WinActivate("User Sign-In", "")
WinWaitActive("User Sign-In", "")
Send("{enter}")

Thanks

Same as I replied above, your solution will be only applicable when you make sure what window is going to pop-up after click to the button, then whatif there could be more than 1 window openned after you click the button.... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged.

Edited by Rota

Share this post


Link to post
Share on other sites
syno

Same as I replied above, your solution will be only applicable when you make sure what window is going to pop-up after click to the button, then whatif there could be more than 1 window openned after you click the button.... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged.

Can you not maximise the offending windows, i.e

WinSetState ( "User-Sign In", "", @SW_MAXIMIZE )

Share this post


Link to post
Share on other sites
Melba23

Rota,

If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there.

Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):

#include <Array.au3>

$aList1 = WinList()

While 1

    $aList2 = WinList()
    If $aList2[0][0] <> $aList1[0][0] Then
        If $aList2[0][0] > $aList1[0][0] Then
            Local $aList3[1]
            For $i = 1 To $aList2[0][0]
                If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then
                    _ArrayAdd($aList3, $aList2[$i][0]) ; [0] for titles or [1] for handles
                    $aList3[0] += 1
                EndIf
            Next
            _ArrayDisplay($aList3)
        EndIf
        $aList1 = $aList2
    EndIf

WEnd

I hope this is useful.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
ChrisL

If you know it's a choice between 2 or 3 windows then you could do this.

$Next_Window = ""
 While 1
     
            Select          
                Case WinExists("Window B Name") 
                    $Next_Window = "B"
                    Exitloop
                    
                Case WinExists("Window C Name") 
                    $Next_Window = "C"
                    Exitloop
                
                Case WinExists("Window D Name") 
                    $Next_Window = "D"
                    Exitloop                
            EndSelect
        Sleep(200)
WEnd
    

Msgbox(0,"","Next window is " & $Next_Window)

Share this post


Link to post
Share on other sites
Rota

Rota,

If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there.

Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):

#include <Array.au3>

$aList1 = WinList()

While 1

    $aList2 = WinList()
    If $aList2[0][0] <> $aList1[0][0] Then
        If $aList2[0][0] > $aList1[0][0] Then
            Local $aList3[1]
            For $i = 1 To $aList2[0][0]
                If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then
                    _ArrayAdd($aList3, $aList2[$i][0]); [0] for titles or [1] for handles
                    $aList3[0] += 1
                EndIf
            Next
            _ArrayDisplay($aList3)
        EndIf
        $aList1 = $aList2
    EndIf

WEnd

I hope this is useful.

M23

Thanks Melba23, actually I also thought the same before while never put it into practice, will try this later and get back to here...

Share this post


Link to post
Share on other sites
Rota

If you know it's a choice between 2 or 3 windows then you could do this.

$Next_Window = ""
 While 1
     
            Select          
                Case WinExists("Window B Name") 
                    $Next_Window = "B"
                    Exitloop
                    
                Case WinExists("Window C Name") 
                    $Next_Window = "C"
                    Exitloop
                
                Case WinExists("Window D Name") 
                    $Next_Window = "D"
                    Exitloop                
            EndSelect
        Sleep(200)
WEnd
    

Msgbox(0,"","Next window is " & $Next_Window)

Thanks, while whenever there is a system response issue, this solution won't work, for example, we expect window C will open after we click to the button, while system response slow, and this window C delay to be openned after 3 s, so the program will winExists the Current window A(in the case clicking button it won't pop-up new window, it remains in Window A), unless we always have the pop-up, this will work, the problem is whatif we don't have extra pop-up window, Window A only refresh itself, how do we detect it?

Share this post


Link to post
Share on other sites
ChrisL

Thanks, while whenever there is a system response issue, this solution won't work, for example, we expect window C will open after we click to the button, while system response slow, and this window C delay to be openned after 3 s, so the program will winExists the Current window A(in the case clicking button it won't pop-up new window, it remains in Window A), unless we always have the pop-up, this will work, the problem is whatif we don't have extra pop-up window, Window A only refresh itself, how do we detect it?

You don't have Window A in as an option in the while loop.

You set $Next_Window = "A"

You add a timer and if none of the other windows appear before the timeout then the $Next_Window variable remains as Window A

$Next_Window = "A"
 $Timer = TimerInit()
 While 1
     
            Select          
                Case WinExists("Window B Name") 
                    $Next_Window = "B"
                    Exitloop
                    
                Case WinExists("Window C Name") 
                    $Next_Window = "C"
                    Exitloop
                
                Case WinExists("Window D Name") 
                    $Next_Window = "D"
                    Exitloop                
            EndSelect
            If TimerDiff($Timer) > 10000 then Exitloop;10 Seconds
        Sleep(200)
WEnd

Share this post


Link to post
Share on other sites
Rota

You don't have Window A in as an option in the while loop.

You set $Next_Window = "A"

You add a timer and if none of the other windows appear before the timeout then the $Next_Window variable remains as Window A

$Next_Window = "A"
 $Timer = TimerInit()
 While 1
     
            Select          
                Case WinExists("Window B Name") 
                    $Next_Window = "B"
                    Exitloop
                    
                Case WinExists("Window C Name") 
                    $Next_Window = "C"
                    Exitloop
                
                Case WinExists("Window D Name") 
                    $Next_Window = "D"
                    Exitloop                
            EndSelect
            If TimerDiff($Timer) > 10000 then Exitloop;10 Seconds
        Sleep(200)
WEnd

Thanks ChrisL, in that case don't you think it would be really time-consuming if the system is working fine, it always need to wait for 10s when there is no extra new windows pop-up... Can you try optimizing it?

Share this post


Link to post
Share on other sites
Rota

Rota,

If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there.

Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):

#include <Array.au3>

$aList1 = WinList()

While 1

    $aList2 = WinList()
    If $aList2[0][0] <> $aList1[0][0] Then
        If $aList2[0][0] > $aList1[0][0] Then
            Local $aList3[1]
            For $i = 1 To $aList2[0][0]
                If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then
                    _ArrayAdd($aList3, $aList2[$i][0]); [0] for titles or [1] for handles
                    $aList3[0] += 1
                EndIf
            Next
            _ArrayDisplay($aList3)
        EndIf
        $aList1 = $aList2
    EndIf

WEnd

I hope this is useful.

M23

I tried the same as you provided, the same problem we faced is if we don't new extra window pop-up, then this loop won't work...cause $aList1[0][0]==$aList2[0][0]...

Share this post


Link to post
Share on other sites
Rota

Just want to reiterate/recap the issue here therefore for better solution coming up....

If we click a Button in Window A to refresh the window/page...

Scenario 1: No Error Occurs. Window A refresh successfully.

Scenario 2: 1st Error Occurs. Window A not refreshed, Window B(error window) pop-up.

Scenario 3: 2nd Error Occurs. Window A not refreshed, Window C(error window) pop-up.

Scenario 4: 3rd Error Occurs. Window A not refreshed, Window D(error window) pop-up.

Special situation: System responses slow, all scenario are delayed for several second.

Then how can we detect all scenario?

Share this post


Link to post
Share on other sites
herewasplato

Let me back up to one thing that you stated/questioned:

"... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged."

You can, but it is not much different than what ChrisL did with WinExists...

winWait timeouts prevent the "hang".

while 1

if winwait(B,"",1) or winwait (C,"",1) or winwait(D,"",1) then exitloop

wend

I'm not saying that this will help you do what you want - I'm just addressing that statement/question.

You might find a solution using the adlib function - but it would be nice to know if there is some info that changes in window (A)

Like:

window (A, "text before refresh")

;code to request refresh

window (A, "during refresh")

while 1

if window (A, "text after refresh", 1) or winwait(B,"",1) or winwait (C,"",1) or winwait(D,"",1) then exitloop

wend

Again, the code that ChrisL or Melba23 provided is more useful since you will know which window appeared... but I thought that I would toss this in along with adlib.

So - is there any text like

window (A, "text before refresh")

and

window (A, "during refresh")

Edit: I see know where you stated that Window (B) is the refresh of Window (A) - sorry missed that in the OP.

Edited by herewasplato

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

Share this post


Link to post
Share on other sites
herewasplato

... it always need to wait for 10s when there is no extra new windows pop-up...

How do you figure that?

In your OP you said:

"When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window,"

In your recap, window B is an error

Which is it?

Edited by herewasplato

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

Share this post


Link to post
Share on other sites
herewasplato

One last post and I'll let you chew of all of my ramblings:

$Next_Window = "A"
;code to request the refresh of Window A
WinWait("Window A Name", "text during refresh")
;or even a pixel function to detect the "awaiting refresh state"
While 1
    Select
        Case WinExists("Window A Name", "has refreshed")
            ExitLoop
            
        Case WinExists("Window B Name")
            $Next_Window = "B"
            ExitLoop

        Case WinExists("Window C Name")
            $Next_Window = "C"
            ExitLoop

        Case WinExists("Window D Name")
            $Next_Window = "D"
            ExitLoop
    EndSelect
    Sleep(200)
WEnd
If you are positive that these are the only windows that you will see AND you can do a winwait for the middle of a refresh of window A then you do not need a timer... unless you just want one for window E that you did not foresee :-) Edited by herewasplato

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

Share this post


Link to post
Share on other sites
Rota

How do you figure that?

In your OP you said:

"When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window,"

In your recap, window B is an error

Which is it?

Sorry for the typo... it should be read as " Click the Button in A window to refresh else pop-up B,C... window if there is an error occur.."

Share this post


Link to post
Share on other sites
Rota

One last post and I'll let you chew of all of my ramblings:

$Next_Window = "A"
;code to request the refresh of Window A
WinWait("Window A Name", "text during refresh")
;or even a pixel function to detect the "awaiting refresh state"
While 1
    Select
        Case WinExists("Window A Name", "has refreshed")
            ExitLoop
            
        Case WinExists("Window B Name")
            $Next_Window = "B"
            ExitLoop

        Case WinExists("Window C Name")
            $Next_Window = "C"
            ExitLoop

        Case WinExists("Window D Name")
            $Next_Window = "D"
            ExitLoop
    EndSelect
    Sleep(200)
WEnd
If you are positive that these are the only windows that you will see AND you can do a winwait for the middle of a refresh of window A then you do not need a timer... unless you just want one for window E that you did not foresee :-)

Thanks herewasplato, this sounds working this time, would look for if there is any text I could define it as "before/during/after refresh" status..

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.