Jump to content
therks

Potential bug with WinWaitClose and [last]

Recommended Posts

WinWait('Task Manager')
ConsoleWrite(WinGetTitle('[last]'))
WinWaitClose('[last]')

Run this, open task manager, close task manager. The ConsoleWrite will print, but the script never closes. 

But if you change the WinWaitClose to a real title, or a handle it works fine.

I don't see this listed in the bug tracker, so I thought I'd ask here if anyone has similar issues before submitting it.

Tested with stable (3.3.14.5) and beta (3.3.15.0), Windows 10 v1909.

Share this post


Link to post
Share on other sites
1 hour ago, therks said:

I don't see this listed in the bug tracker, so I thought I'd ask here if anyone has similar issues before submitting it.

Same behavior with Windows 7 and AutoIt 3.3.14.0. WinWaitClose does not accept [Last] (as you wrote), not even [Active] .

This works (as you know) :

WinWait('Windows Task-Manager') ; my title in german
ConsoleWrite("1. WinGetTitle = " & WinGetTitle("[Last]") & @CRLF)
WinWaitClose(WinGetTitle("[Last]"))
ConsoleWrite("2. CLOSED" & @CRLF)

But I don't think that should be considered as a bug.


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

Share this post


Link to post
Share on other sites
1 hour ago, Musashi said:

 

But I don't think that should be considered as a bug.

Why not? It's inconsistent behaviour. If it doesn't get fixed then the next person wondering why it doesn't work will come here wondering why as well. Considering the lack of updates I'm not expecting it to get fixed any time soon, but it should be recorded at least.

Share this post


Link to post
Share on other sites
4 hours ago, therks said:

Why not? It's inconsistent behaviour. [...] Considering the lack of updates I'm not expecting it to get fixed any time soon, but it should be recorded at least. 

After reconsideration, I have come to the conclusion that you are right.

E.g. WinExists reports true even if the window has already been closed. Here is a little script to play around with :lol::

HotKeySet("{ESC}", "_Terminate")
Local $iCount = 0

WinWait('Windows Task-Manager') ; title in german (==> use titel in your language instead, e.g. 'Task Manager')
ConsoleWrite("> >>>> WinGetTitle = " & WinGetTitle("[LAST]") & @CRLF)

; just a check : "[LAST]" with WinExists
If WinExists("[LAST]") Then
    ConsoleWrite("> >>>> WinExists = TRUE" & @CRLF)
Else
    ConsoleWrite("! >>>> WinExists = FALSE" & @CRLF)
EndIf

; just a check : "[LAST]" with WinActive
If WinActive("[LAST]") Then
    ConsoleWrite("> >>>> WinActive = TRUE" & @CRLF)
Else
    ConsoleWrite("! >>>> WinActive = FALSE" & @CRLF)
EndIf


; ===========================================================
; Remove the comment for the desired area :
; ===========================================================

; Variation 1 : WinWaitClose
;~ WinWaitClose("[LAST]") ; <=== waits endlessly
;~ WinWaitClose(WinGetTitle("[LAST]")) ; <=== works

; Variation 2 : WinClose <=== works
;~ Sleep(2000)
;~ WinClose("[LAST]")

; Variation 3 : While WinExists <=== runs endlessly
While WinExists("[LAST]")
    ConsoleWrite("> >>>> While WinExists -> " & $iCount & @CRLF)
    $iCount += 1
    Sleep(250)
WEnd

; Final message :
ConsoleWrite("> >>>> CLOSED" & @CRLF)

Func _Terminate()
    ConsoleWrite("! >>>> TERMINATED by ESC" & @CRLF)
    Exit
EndFunc   ;==>_Terminate

 

Edited by Musashi
typo

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

Share this post


Link to post
Share on other sites

Wow, yeah that is interesting. I wonder what the [LAST] keyword is doing internally. I assumed that when AutoIt did title matching it was just saving the handle from the most recent title match, and swapping that in whenever it encountered the [LAST] keyword, but I just tried this:

$iCount = 0
HotKeySet('{ESC}', '_Exit')

WinWait('[CLASS:TaskManagerWindow]') ; Let's use the classname so we don't have to translate each time ;)

Do
    $iCount += 1
    ConsoleWrite($iCount & ') =============================================' & @CRLF)
    ConsoleWrite('WinGetHandle: ' & WinGetHandle('[last]') & @CRLF) ; Always returns a valid handle
    ConsoleWrite('WinExists: ' & WinExists('[last]') & @CRLF) ; Always returns 1
    ConsoleWrite('WinGetHandle(WinGetHandle): ' & WinGetHandle(WinGetHandle('[last]')) & @CRLF) ; Properly returns 0
    ConsoleWrite('WinExists(WinGetHandle): ' & WinExists(WinGetHandle('[last]')) & @CRLF) ; Properly returns 0
Until WinWaitClose('[last]', '', 1)
;Until WinWaitClose(WinGetHandle('[last]'), '', 1) ; <- This line will detect properly

Func _Exit()
    Exit
EndFunc

And as you'll see, WinGetHandle on [LAST] will give the same handle even after the window is closed, but WinGetHandle ON that handle, will return 0. So if it were a simple swap of [LAST] for an HWND, then the first WinGetHandle would also return 0. Maybe someone in the know can weigh in and explain what's happening with [LAST] behind the scenes. :)

Share this post


Link to post
Share on other sites
18 minutes ago, therks said:

So if it were a simple swap of [LAST] for an HWND, then the first WinGetHandle would also return 0. Maybe someone in the know can weigh in and explain what's happening with [LAST] behind the scenes. :)

Yes, I can confirm the process flow that you described.

I also expected [LAST] to be converted / swapped internally into a handle. We really need somebody who has a deeper insight into the processes in the background 😛.


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

Share this post


Link to post
Share on other sites
Posted (edited)

Hi Jon, just to confirm:

You're saying it doesn't make sense that it would behave that way, but are you seeing the same results with our test scripts?

Edited by therks
Better wording

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...