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

StackOverflow https://stackoverflow.com/questions/4382145

  •  09-10-2019
  •  | 
  •  

سؤال

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 (wich actually is already hidden), and then IE makes the dialog visible wich results in a visible dialog(!).

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

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top