Jump to content

How to check if a certain window has appeared


doctorq
 Share

Recommended Posts

Hi,

I'm a new user on this forum, and am also fairly new at coding in AutoIT. Now I'm unfortunately stuck so I turn to this forum, and can hopefully get some help from people more skilled at AutoIT than I am myself.

I'm trying to code some automation for a fairly odd program we use at my workplace, lets call it "foo". It has a simple layout, is a very static program, as menus, buttons, text, etc is always at the same spot. The only thing that is changing, is for instance the username logging into the program, and a date field that obviously changes daily.

I can automate the process of starting "foo". A loading screen (again a static window) will show, with the title "foo". I can therefore use WinExists function to check if the program is loading. My problem is though, that when the loading screen isn't showing anymore, it is replaced with a new screen with the exact same title; "foo".

I can't use the WinExists function to check for the new screen, as the title is the same as the loading screen.

I can't just sleep the program, since there can be loading time outs, no network connection or other errors preventing the program to start, or not showing the right windows at the right time.

I can't add any text to search for, as the autoit window info tells me there are no hidden og visable text in the window I need to deal with. 

I have tried to use PixelChecksum of certain smaller areas of the screen that displays after the loading screen, but to no avail. I get different values from the pixelchecksum function, if I change screen resolution, or change the screen zoom. Maybe I'm just using the PixelChecksum function incorrectly? My understanding is that it will return the same value every time, if the window in question is the same every time, regardless of other settings. The program I need to program, needs to be able to run (and function proberly) without dependencies to other settings.

I hope someone either have a different way of finding static areas, or break down the pixelchecksum function down to dummy mode, as I can't get the expected result out of the function.

 

Thanks in advance!

Link to comment
Share on other sites

You could use WinWait to find the first loading screen and store the window handle in a variable. Then in a loop, use WinWait to find the second loading screen whilst checking that the window handle of the second loading screen is different to the first.

Quick example using Calculator:

Local $hWnd[2]

$hWnd[0] = WinWait('Calculator')
If IsHWnd($hWnd[0]) = 1 Then
    While 1
        $hWnd[1] = WinWait('Calculator')
        If IsHWnd($hWnd[1]) = 1 Then
            If $hWnd[1] = $hWnd[0] Then ContinueLoop
            ConsoleWrite('I found the second instance of Calculator' & @CRLF)
            ConsoleWrite('$hWnd[0] = ' & $hWnd[0] & @CRLF)
            ConsoleWrite('$hWnd[1] = ' & $hWnd[1] & @CRLF)
            ExitLoop
        EndIf
        Sleep(100)
    WEnd
Else
    ConsoleWrite('I could not find the first instance of Calculator' & @CRLF)
EndIf

Run the script, open a Calculator instance. Close it. (optional) Run another Calculator instance.

Edited by Luke94
Link to comment
Share on other sites

Maybe you could use other attributes of the windows.  Does loading screen have different size of the app screen ?  Does loading screen appear in the exact same spot as the app screen ?  Maybe the windows type is different (border or close button or menu) ?  Maybe loading screen is more static pixel wise, so instead of checking app pixels, you could check for pixel inside loading screen (last resort, as I do not like much using pixel* in automating applications).  There should be someways to differentiate those two windows.

In any case, if you can't find a solution, you might want to capture both screens (and post images here) so we can think of another approach.

ps.  be careful with WinWait.  If you do not specify a timeout, it will wait forever.  And I am not sure it is appropriate to your situation.  If you do not catch the loading screen then the script is useless.

Link to comment
Share on other sites

Thanks for your reply and your possible solution, that actually works very well. I'll see if I can adapt it to my program and get it to work as intended.

Still interested in other solutions though. I found the WinSetTitle function, to which I can manipulate the window title, and then just compare window titles to eachother.

Link to comment
Share on other sites

4 minutes ago, Nine said:

Maybe you could use other attributes of the windows.  Does loading screen have different size of the app screen ?  Does loading screen appear in the exact same spot as the app screen ?  Maybe the windows type is different (border or close button or menu) ?  Maybe loading screen is more static pixel wise, so instead of checking app pixels, you could check for pixel inside loading screen (last resort, as I do not like much using pixel* in automating applications).  There should be someways to differentiate those two windows.

In any case, if you can't find a solution, you might want to capture both screens (and post images here) so we can think of another approach.

ps.  be careful with WinWait.  If you do not specify a timeout, it will wait forever.  And I am not sure it is appropriate to your situation.  If you do not catch the loading screen then the script is useless.

In the meantime since posting, I have actually done some of your suggestions by checking the size of the loading screen, so I know which screen is being displayed.

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