/// <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 void SelectLoginType(FakeClientWindow fcw) { int delay = 500; Thread.Sleep(delay); System.Drawing.Rectangle qqBox = fcw.QQBox; var a = (int)((qqBox.Left + qqBox.Width) * Helper.Rate); var b = (int)((qqBox.Top + qqBox.Height) * Helper.Rate); //ClickOnPointTool.ClickOnPoint(fcw.InnerWindow.Handle, // new System.Drawing.Point((int)((qqBox.Left + qqBox.Width) * Helper.Rate), // (int)((qqBox.Top + qqBox.Height) * Helper.Rate))); ; fcw.InnerWindow.DoMouseClick((int)((qqBox.Left + qqBox.Width) * Helper.Rate), (int)((qqBox.Top + qqBox.Height) * Helper.Rate)); }
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); }
private void EnterPassword(FakeClientWindow fcw) { int delay = 500; Thread.Sleep(delay); string password = PasswordManager.Load(); System.Drawing.Rectangle passwordBox = fcw.PasswordBox; // erase whatever is in the password box (double-click selects everything) fcw.InnerWindow.SendMouseClick(passwordBox.Left + passwordBox.Width / 2, passwordBox.Top + passwordBox.Height / 2); fcw.InnerWindow.SendMouseClick(passwordBox.Left + passwordBox.Width / 2, passwordBox.Top + passwordBox.Height / 2); fcw.InnerWindow.Parent.SendKey(VirtualKeyCode.BACK); fcw.InnerWindow.Parent.SendText(password); fcw.InnerWindow.Parent.SendKey(VirtualKeyCode.RETURN); }
private System.Drawing.Rectangle GetPasswordRect(FakeClientWindow clientWindow) { // check that the handle is valid if (clientWindow == null) { return(System.Drawing.Rectangle.Empty); } var result = System.Drawing.Rectangle.Empty; if (clientWindow.Status == ClientStatus.OnLoginScreen) { result = clientWindow.PasswordBox; } GC.Collect(); return(result); }