Jump to content

Recommended Posts

Posted

I'm using ControlSend() to a main application window which will then bring up a sub-window (pop-up?), and then wait for that second window to become active (using WinWaitActive()), at which point I perform more actions. The problem I'm having is that the WinWaitActive() always hangs.  Here's the code snippet:

$Lf_Stat = ControlSend( $Lf_WinHandle, "", "", "!c" )
    If $Lf_Stat <> 1 Then Return
    
    $Lf_Stat = WinWaitActive ( "Copy To Folder", "", 30 )
    If $Lf_Stat <> 1 Then
        Beep( 750, 400 )
        Return
    EndIf

Now, I know that the "Copy To Folder" sub-window does indeed become active almost immediately during my debugging tests, but there's no guarantee that will always be the case, especially if the system is very busy.  That's why I need the WinWaitActive() with timeout. But what appears to be happening is that if the window is already active when the WinWaitActive() call is reached, the call does NOT immediately return successfully (as I would certainly expect), but instead always hangs and waits until the time-out!

Is my expectation wrong?  Is WinWaitActive() supposed to wait if the window in question is already active?  Or am I making some other dumb mistake?

 

Posted (edited)
3 hours ago, Mbee said:

I'm using ControlSend() to a main application window which will then bring up a sub-window (pop-up?), and then wait for that second window to become active (using WinWaitActive()), at which point I perform more actions. The problem I'm having is that the WinWaitActive() always hangs. 

 

Can you try this instead:

$Lf_Stat = ControlSend($Lf_WinHandle, "", "", "!c" )
    If $Lf_stat = 1 then
    
        $Lf_Stat = WinWaitActive("Copy To Folder", "", 30 )
        If $Lf_Stat <> 0 Then ;since 0 is the return value for failed handles
        Beep( 750, 400 )
        Return
        else
          ;do more stuff here if needed be`
        endif
       
    Else
        Return
    EndIf

I just re-arranged the process. If this doesn't work there is a possibility that we'll be needing to see more of the script.

~XN~

Edited by XaelloNegative
Forgot to add comments and use endif. sorry.

;) ~XN~ ;)

Posted (edited)
1 hour ago, XaelloNegative said:

Can you try this instead:

$Lf_Stat = ControlSend($Lf_WinHandle, "", "", "!c" )
    If $Lf_stat = 1 then
    
        $Lf_Stat = WinWaitActive("Copy To Folder", "", 30 )
        If $Lf_Stat <> 0 Then ;since 0 is the return value for failed handles
        Beep( 750, 400 )
        Return
        else
          ;do more stuff here if needed be`
        endif
       
    Else
        Return
    EndIf

I just re-arranged the process. If this doesn't work there is a possibility that we'll be needing to see more of the script.

~XN~

Thank you for your reply, but I've already changed my code slightly and it seems to work now.  Here is how it reads now:

$Lf_ACDSeePID = ProcessExists( $GC_ACDSeeProcName )
    If $Lf_ACDSeePID = 0 Then Return

    $Lf_MainWinHdl = WinActive( $GC_ACDSeeTitle )
    If $Lf_MainWinHdl = 0 Then
        $Lf_MainWinHdl = WinActivate( $GC_ACDSeeTitle )
        If $Lf_MainWinHdl = 0 Then
            StatusMsgs_WriteLine("Main WinActivate Failed")
            Beep( 400, 400 )
            Return
        EndIf
    EndIf

    $Lf_Stat = ControlSend( $Lf_MainWinHdl, "", "", "!c" )
    If $Lf_Stat <> 1 Then
        StatusMsgs_WriteLine("Main ControlSend (copy) Failed")
        Beep( 500, 400 )
        Return
    EndIf

    $Lf_SubWinHdl = WinActive( "Copy To Folder" )
    If $Lf_SubWinHdl = 0 Then
        StatusMsgs_WriteLine("Had to WinWaitActive() SubWindow")
        $Lf_SubWinHdl = WinWaitActive ( "Copy To Folder", "", 30 )
        If $Lf_SubWinHdl= 0 Then
            StatusMsgs_WriteLine("WinWaitActive() Timed Out")
            Beep( 600, 400 )
            Return
        EndIf
    EndIf

    $Lf_Stat = ControlClick( $Lf_SubWinHdl, "", "OK" )
    If $Lf_Stat <> 1 Then
        StatusMsgs_WriteLine("First ControlClick (copy) Failed")
        Beep( 700, 400 )
        Return
    EndIf

    Sleep( 1000 )
    Return

When I run this, the StatusMsg log shows: "Had to WinWaitActive() SubWindow"

However, I'd still like the answer to the main question in my OP: Is WinWaitActive() supposed to wait if the window in question is already active?

Edited by Mbee
Posted (edited)

I take it back. When I comment-out all the StatusMsgs...() calls, it times out again! WTF?

Let me spend more time working on this before anyone bothers replying again. There must be something about the circumstances that I don't understand.  If I need more help, I'll ask...

 

Edited by Mbee
Posted

Okay, it works now.  It turns out that ACDSee 9 doesn't always recognize the "ALT c" ControlSend, and when it doesn't, obviously any WinWaitActive() is going to time out.  So when that happens, you have to send it again and again until it is recognized (within reason).  So this code works correctly:

Func ACDSeeCopy()

    Local $Lf_Stat, $Lf_MainWinHdl, $Lf_SubWinHdl, $Lf_ACDSeePID, $Lf_SubWinReady, $Lf_SubWinLoopCount

    $Lf_ACDSeePID = ProcessExists( $GC_ACDSeeProcName )
    If $Lf_ACDSeePID = 0 Then Return

    $Lf_MainWinHdl = WinActive( $GC_ACDSeeTitle )
    If $Lf_MainWinHdl = 0 Then
        $Lf_MainWinHdl = WinActivate( $GC_ACDSeeTitle )
        If $Lf_MainWinHdl = 0 Then
            Beep( 400, 400 )
            Return
        EndIf
    EndIf

    $Lf_Stat = ControlSend( $Lf_MainWinHdl, "", "", "!c" )
    If $Lf_Stat <> 1 Then
        Beep( 750, 400 )
        Return
    EndIf

    $Lf_SubWinLoopCount = 0
    $Lf_SubWinReady = False
    While (Not $Lf_SubWinReady) And ($Lf_SubWinReady < 30)
        $Lf_SubWinHdl = WinActive( "Copy To Folder" )
        If $Lf_SubWinHdl = 1 Then
            $Lf_SubWinReady = True
        Else
            $Lf_SubWinHdl = WinWaitActive ( "Copy To Folder", "", 2 )
            If $Lf_SubWinHdl <> 0 Then
                $Lf_SubWinReady = True
            Else
                $Lf_SubWinLoopCount += 1
                $Lf_Stat = ControlSend( $Lf_MainWinHdl, "", "", "!c" )
                If $Lf_Stat <> 1 Then
                    Beep( 750, 400 )
                    Return
                EndIf
            EndIf
        EndIf
    WEnd

    If Not $Lf_SubWinReady Then     ; LOOP COUNT EXCEEDED!
        Beep( 900, 400 )
        Return
    EndIf

    $Lf_Stat = ControlClick( $Lf_SubWinHdl, "", "OK" )
    If $Lf_Stat <> 1 Then
        Beep( 1000, 400 )
        Return
    EndIf

    Return

EndFunc
;

 

 

Thanks for your patience.

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