/// <summary> /// 获取窗体句柄 /// </summary> /// <returns></returns> private FakeClientWindow GetClientWindow() { List <FakeWindow> windows = Helper.GetWindows(Constances.TCLS_ROOT_CLIENT_Name, Constances.TCLS_ROOT_CLIENT_Title); //List<FakeWindow> windows = Helper.GetWindows(Constances.ROOT_CLIENT_CLASS, null); foreach (FakeWindow window in windows) { FakeWindow child = window.FindChildRecursively(window.Handle, null, null); if (child == null) { continue; } FakeClientWindow fcw = new FakeClientWindow(window.Handle, window.Parent, window.ClassName, window.Name, child); fcw.RefreshStatus(); if (fcw.IsMatch) { return(fcw); } } return(null); }
/// <summary> /// 等待获取窗体句柄 /// </summary> /// <returns></returns> private FakeClientWindow AwaitClientHandle() { var sw = new Stopwatch(); sw.Start(); FakeClientWindow fcw = GetClientWindow(); // search for window until client timeout is reached or window is found while (sw.ElapsedMilliseconds < timeout && (fcw == null || fcw.Status == ClientStatus.Unknown)) { Thread.Sleep(1000); if (fcw != null) { fcw.RefreshStatus(); } else { fcw = GetClientWindow(); } } return(fcw); }
private System.Drawing.Rectangle WaitForPasswordBox(FakeClientWindow fcw) { // loop while not found and while client handle is something try { while (fcw.Exists() && fcw.Status != ClientStatus.OnLoginScreen) { Thread.Sleep(500); fcw.RefreshStatus(); } } catch (Exception ex) { AppendTrace($"Failed to refresh the client window's state:{ex.Message}", Brushes.Red); } // return whether client was found or not return(fcw.PasswordBox); }