Jump to content

Window passes WinWaitActive before visible


Go to solution Solved by hennenzac,

Recommended Posts

Posted

Hello,

Running into an issue with WinWaitActive.  I use this to detect a certain window is active by using it's handle which I confirmed its detecting the correct window.  Once active, I move the window to 0,0 position so I can mouse click things within that window.  This was working for some time but, for some reason, my computer is getting slow or what, but the script continues on and gets off track because it does not move the window to 0,0 but continues the script so the clicks are off.

I looked in the help file and in the example for WinWaitActive, they even have a delay for waiting 2 sec for the window to display.  I rather avoid timing delays for reliability.  Is there a way to avoid this delay?  I looked at all the other window wait functions and nothing really helps if it already thinks it's active.  Maybe loop until window is at position 0,0?  Haven't tried that yet.

 

Thanks.

;waits for explorer window to show and positions it to 0,0
$hcheckwin= WinWaitActive("Check out project")
ConsoleWrite("Window found: "& $hcheckwin & @CRLF)
Sleep(3000)
WinMove($hcheckwin,"",0,0)
Posted

FWIW, the pause in the example script appears to be there simply to allow the window to be visible for a period of time before closing it. Are you sure the value of $hcheckwin is correct? If so, then you could always loop until the window has moved.

There are usually better ways to automate an application than using mouse clicks. Can you tell us which application you are automating?

Posted

If WinWaitActive returns (of course without a timeout, like op did), it is because it has found a window, otherwise it would wait forever.

So testing for the handle is not necessary, and sleep should not be there as well.

I wonder if your "Check out project" application has been upgraded, changed, or something in the mean time ?

Posted (edited)

As @Nine  has already described : 


WinWaitActive waits forever if no window has been found. Conversely, this also means that WinMove is executed as soon as WinWaitActive supplies a handle (Sleeps are not required - Timeouts only so that the process ends at some point). 
Run the following two-liner and then start Notepad whenever you want. As soon as Notepad is recognized as active, a move takes place immediately.

Local $hCheckWin = WinWaitActive("[CLASS:Notepad]", "") ; polled every 250 milliseconds 
WinMove($hCheckWin, "", 0, 0)

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted
21 minutes ago, ioa747 said:
;waits 3sec for explorer window to show and positions it to 0,0
$hcheckwin = WinWaitActive("Check out project", "", 3)
If $hcheckwin Then
    ConsoleWrite("Window found: " & $hcheckwin & @CRLF)
    WinMove($hcheckwin, "", 0, 0)
Else
    ConsoleWrite("Window not found" & @CRLF)
EndIf

 

It looks you cleaned up what I had written but with an if statement.  This code will still have the problem of moving on in the script because the $hcheckwin will still be true before it shows up on the screen.  I need it to delay 3 seconds after its detected in order for the move to work.  Thank you for the reply.

 

 

23 minutes ago, Danp2 said:

FWIW, the pause in the example script appears to be there simply to allow the window to be visible for a period of time before closing it. Are you sure the value of $hcheckwin is correct? If so, then you could always loop until the window has moved.

There are usually better ways to automate an application than using mouse clicks. Can you tell us which application you are automating?

Good point on the example script in the help file.

To verify the handle, I console write it so I can see the name in the console.  Before the script continues, I stop the script then check the handle with the AutoIt Window Info tool and they matched.

In short, what I'm doing is loading a file into a program.  When I click the "Check Out" button in my program, it opens a file explorer window to navigate to the file to open.  The tricky thing is this is in our PDM system and it changes how the explorer works/looks vs. native windows explorer.  Thus, I have to "click" on the address bar to select and input the address to navigate to the folder where the file is, and then "double click" the file in the folder (it's the only one all the time) to open it.  No amount of TAB will get me to the file.  

Thanks for the reply.

Posted
31 minutes ago, Musashi said:

As @Nine  has already described : 


WinWaitActive waits forever if no window has been found. Conversely, this also means that WinMove is executed as soon as WinWaitActive supplies a handle (Sleeps are not required - Timeouts only so that the process ends at some point). 
Run the following two-liner and then start Notepad whenever you want. As soon as Notepad is recognized as active, a move takes place immediately.

Local $hCheckWin = WinWaitActive("[CLASS:Notepad]", "") ; polled every 250 milliseconds 
WinMove($hCheckWin, "", 0, 0)

 

I understand what you are saying an I agree that's how I interpreted how it works, but the window does not move even after passing the WinWaitActive.  The mouse loading icon is going on loading the windows explorer and the script moves on before the window is visible.  Thanks for the reply.

  • Solution
Posted

I added a loop to keep trying to move the window until it's in 0,0 position.  Probably the more brute force way, but it appears to be working.  I added a counter so it can "timeout" and not be stuck infinitely.  Not super clean but should work.  Any other ideas or feedback is welcome.

;waits for explorer window to show and positions it to 0,0
    $hcheckwin= WinWaitActive("Check out project")
    ConsoleWrite("Window found: "& $hcheckwin & @CRLF)
    Sleep(1500)
    $counter = 0
    Do
        WinMove($hcheckwin,"",0,0)
        Sleep(250)
        $winPos = WinGetPos($hcheckwin)
        $counter = $counter+1
        If $counter >20 Then Exit
    Until $winPos[0] = 0 AND $winPos[1] = 0

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...