Search code examples
windowsautomationautoit

Is there a way to make AutoIt's WinWaitActive care about if a window is visible


My script is supposed to wait for the "Select File" dialog of IE to appear, then make it go away and replace it with a custom select file interface. I've gotten it all working, but there is one thing nagging me. The code is as following:

WinWaitActive("Select File")
WinSetState("Select File", "", @SW_HIDE)

The problem seems to be that the "Select File" dialog is (invisibly) created by IE, made active, then made visible. It's a basic threading problem really:

In some cases, IE makes the dialog active (but not visible yet!). My script picks that up, Hides the dialog (which actually is already hidden), and then IE makes the dialog visible which results in a visible dialog(!).

Is there any option I can set which makes the WinWaitActive command also wait for the window the be visible, not just active?


Solution

  • you can use the function below to know if the window is visible.

    Func IsWindowVisible($handle)
        If BitAnd(WinGetState($handle), 2) Then 
            Return 1
        Else
            Return 0
        EndIf
    EndFunc
    

    then you can use a loop like this to do what you want:

    While 1
        If IsWindowVisible(FindWindow("Select File", "")) Then ; I'm not sure about FindWindow syntax
            WinSetState("Select File", "", @SW_HIDE)
            Break
        Else
            Sleep (1000)
        EndIf
    EndWhile
    

    Hope this helps.