Jump to content

Does not go back to previous window.


Recommended Posts

Basically what happens is 2 programs I use at work timeout after so much time. This sits in tray and clicks the ok button to stop timeout. What im trying to do is after button clicks, go back to page you were on previously.

Can someone see what I'm doing wrong?

Thanks!

Func stoptimeout()
    Opt("WinTitleMatchMode", 2) 
    If WinExists ("Microsoft Internet Explorer", "Application timeout will occur in 10 minutes") Then 
        $CurrentWindow = WinGetHandle("")
        ControlClick ("Microsoft Internet Explorer", "", 1, "left", 1)
        WinSetState($CurrentWindow,"",@SW_SHOW)
        
        EndIf
    If WinExists ("Session time-out alert", "Your DSN session is about to time out.") Then 
        $CurrentWindow = WinGetHandle("")
        ControlClick ("Session time-out alert", "", 6, "left", 1)
        WinSetState($CurrentWindow,"",@SW_SHOW)
        
        EndIf
        
        Sleep(10)

EndFunc   ;==>Stoptimeout
Link to comment
Share on other sites

Basically what happens is 2 programs I use at work timeout after so much time. This sits in tray and clicks the ok button to stop timeout. What im trying to do is after button clicks, go back to page you were on previously.

Can someone see what I'm doing wrong?

Try WinActivate() vice WinSetState().

:-)

P.S. With just the handle, i.e. WinActivate($CurrentWindow)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Try WinActivate() vice WinSetState().

:-)

P.S. With just the handle, i.e. WinActivate($CurrentWindow)

I tried that.. Didn't work. :rolleyes: Clicks the button and stays on the page that was going to time out.

What I think is happening is when the window pops open that is timing out, it is capturing the title of that window, instead of the window that was being worked on before the popup. You have any ideas on what I could do about this?

Edited by Klexen
Link to comment
Share on other sites

I tried that.. Didn't work. :rambo: Clicks the button and stays on the page that was going to time out.

What I think is happening is when the window pops open that is timing out, it is capturing the title of that window, instead of the window that was being worked on before the popup. You have any ideas on what I could do about this?

Hmm... interesting. This works for me. Try _WinPrevious() on yours:

Run("notepad.exe")

WinWait("Untitled - ")
ControlClick("Untitled - ", "", 1, "left", 1)
Sleep(500)
Send("Hello")
Sleep(2000)

If Not _WinPrevious() Then MsgBox(16, "Error", "_WinPrevious() returned 0, and @error = " & @error)


; =======================================
; Function _WinPrevious()
;   Activates a previous window in the z-order.  Only counts visible
;       windows with non-blank titles.
;   Call with:  _WinPrevious([$z])
;       Where:  $z = number of steps back in the z-order (default is 1)
;   On success, returns 1 and activates the previous visible window
;   On failure, returns 0 and sets @error
; =======================================
Func _WinPrevious($z = 1)
    If $z < 1 Then Return SetError(1, 0, 0) ; Bad parameter
    Local $avList = WinList()
    For $n = 1 to $avList[0][0]
        ; Test for non-blank title, and is visible
        If $avList[$n][0] <> "" And BitAND(WinGetState($avList[$n][1]), 2) Then
            If $z Then 
                $z -= 1
            Else
                WinActivate($avList[$n][1])
                Return 1
            EndIf
        EndIf
    Next
    Return SetError(2, 0, 0) ; z-depth exceeded
EndFunc

:rolleyes:

P.S. _WinPrevious() defaults to one level back in the z-order. But if that isn't far enough, you can pass an optional higher number, like _WinPrevious(2) to go two levels back, etc.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hmm... interesting. This works for me. Try _WinPrevious() on yours:

Run("notepad.exe")

WinWait("Untitled - ")
ControlClick("Untitled - ", "", 1, "left", 1)
Sleep(500)
Send("Hello")
Sleep(2000)

If Not _WinPrevious() Then MsgBox(16, "Error", "_WinPrevious() returned 0, and @error = " & @error)
; =======================================
; Function _WinPrevious()
;   Activates a previous window in the z-order.  Only counts visible
;       windows with non-blank titles.
;   Call with:  _WinPrevious([$z])
;       Where:  $z = number of steps back in the z-order (default is 1)
;   On success, returns 1 and activates the previous visible window
;   On failure, returns 0 and sets @error
; =======================================
Func _WinPrevious($z = 1)
    If $z < 1 Then Return SetError(1, 0, 0) ; Bad parameter
    Local $avList = WinList()
    For $n = 1 to $avList[0][0]
        ; Test for non-blank title, and is visible
        If $avList[$n][0] <> "" And BitAND(WinGetState($avList[$n][1]), 2) Then
            If $z Then 
                $z -= 1
            Else
                WinActivate($avList[$n][1])
                Return 1
            EndIf
        EndIf
    Next
    Return SetError(2, 0, 0) ; z-depth exceeded
EndFunc

:rolleyes:

P.S. _WinPrevious() defaults to one level back in the z-order. But if that isn't far enough, you can pass an optional higher number, like _WinPrevious(2) to go two levels back, etc.

_WinPrevious() actually worked!! You're awesome. I was going to do an ALT+TAB after button was clicked. But this is definately a better option. Thanks so much!
Link to comment
Share on other sites

_WinPrevious() actually worked!! You're awesome. I was going to do an ALT+TAB after button was clicked. But this is definately a better option. Thanks so much!

You're welcome. The idea came from a post by Larry about z-order. This function may have been done elsewhere (and better), but this works for me.

Glad it helped!

:rolleyes:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...