public bool IsChildWindow(Window window) { var mainWindow = new Window(_mainIeHwnd); return _ieVersion < 8 ? DialogBelongsToIEWindowForIe7AndLower(window, mainWindow) : DialogBelongsToIEWindowForIe8AndHigher(window, mainWindow); }
public virtual void Close() { var dialog = new Window(hwnd); if (dialog.Visible) { dialog.ForceClose(); } base.Dispose(true); }
/// <summary> /// Handles the logon dialog by filling in the username and password. /// </summary> /// <param name="window">The window.</param> /// <returns></returns> public override bool HandleDialog(WatiN.Core.Native.Windows.Window window) { if (runonce) { return(false); } if (CanHandleDialog(window)) { runonce = true; // Find Handle of the "Frame" and then the combo username entry box inside the frame var systemCredentialsHwnd = GetSystemCredentialsHwnd(window); SetActiveWindow(window.Hwnd); Thread.Sleep(1000); SetForegroundWindow(window.Hwnd); Thread.Sleep(1000); var windowEnumarator = new WindowsEnumerator(); var all = windowEnumarator.GetChildWindows(systemCredentialsHwnd); // Find input fields var edits = windowEnumarator.GetChildWindows(systemCredentialsHwnd, "Edit"); Thread.Sleep(2000); // Enter userName var hwnd = new Hwnd(edits[0].Hwnd); hwnd.SetFocus(); clearText(hwnd); hwnd.SendString(userName); hwnd.SendMessage(0x0102, '\t', 0); hwnd = null; Thread.Sleep(2000); // Enter password hwnd = new Hwnd(edits[1].Hwnd); hwnd.SetFocus(); clearText(hwnd); hwnd.SendString(password); // Click OK button var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button" && new WinButton(w.Hwnd).Title == "OK").FirstOrDefault(); if (windowButton != null) { new WinButton(windowButton.Hwnd).Click(); } //new WinButton(1, window.Hwnd).Click(); //new WinButton(0, window.Hwnd).Click(); return(true); } return(false); }
private static bool DialogBelongsToIEWindowForIe8AndHigher(Window dialog, Window mainWindow) { Logger.LogDebug("Main: " + mainWindow.Hwnd + ", " + mainWindow.Title + ", " + mainWindow.ProcessID); var hWnd = IEUtils.GetInteretExplorerServerHwnd(mainWindow.Hwnd); var window1 = new Window(hWnd); Logger.LogDebug("IES: " + window1.Hwnd + ", " + window1.Title + ", " + window1.ProcessID); return window1.ProcessID == dialog.ProcessID; }
private IntPtr GetSystemCredentialsHwnd(WatiN.Core.Native.Windows.Window window) { var hwnd = NativeMethods.GetChildWindowHwnd(window.Hwnd, "SysCredential"); // IE8 doesn't have the SysCredentails frame any more. if (hwnd == IntPtr.Zero) { hwnd = NativeMethods.GetChildWindowHwnd(window.Hwnd, "DirectUIHWND"); } return(hwnd); }
public IList<Window> GetChildWindows(IntPtr hwnd, WindowEnumConstraint constraint) { var childWindows = new List<Window>(); NativeMethods.EnumChildWindows(hwnd, (childHwnd, lParam) => { var childWindow = new Window(childHwnd); if (constraint == null || constraint(childWindow)) childWindows.Add(childWindow); return true; }, IntPtr.Zero); return childWindows; }
public IList<Window> GetWindows(WindowEnumConstraint constraint) { var windows = new List<Window>(); NativeMethods.EnumWindows((hwnd, lParam) => { var window = new Window(hwnd); if (constraint == null || constraint(window)) windows.Add(window); return true; }, IntPtr.Zero); return windows; }
/// <summary> /// Determines whether the specified window is a logon dialog. /// </summary> /// <param name="window">The window.</param> /// <returns> /// <c>true</c> if the specified window is a logon dialog; otherwise, <c>false</c>. /// </returns> public override bool CanHandleDialog(WatiN.Core.Native.Windows.Window window) { // If a logon dialog window is claimsFolder_Found hWnd will be set. return(GetSystemCredentialsHwnd(window) != IntPtr.Zero); }
private static void WaitUntilVisibleOrTimeOut(Window window) { // Wait untill window is visible so all properties // of the window class (like Style and StyleInHex) // will return valid values. /*var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut)); var success = tryActionUntilTimeOut.Try(() => window.Visible); if (!success) { Logger.LogAction("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut); }*/ }
/// <summary> /// If the window is a dialog and visible, it will be passed to /// the registered dialog handlers. I none if these can handle /// it, it will be closed if <see cref="CloseUnhandledDialogs"/> /// is <c>true</c>. /// </summary> /// <param name="window">The window.</param> public void HandleWindow(Window window) { if (!window.IsDialog()) return; // This is needed otherwise the window Style will return a "wrong" result. WaitUntilVisibleOrTimeOut(window); // Lock the thread and see if a handler will handle // this dialog window lock (this) { /* foreach (var dialogHandler in _handlers) { try { if (dialogHandler.CanHandleDialog(window, MainWindowHwnd)) { if (dialogHandler.HandleDialog(window)) return; } } catch (Exception e) { LastException = e; Logger.LogAction("Exception was thrown while DialogWatcher called HandleDialog: {0}",e.ToString()); } } */ // If no handler handled the dialog, see if the dialog // should be closed automatically. //if (!CloseUnhandledDialogs || MainWindowHwnd != window.ToplevelWindow.Hwnd) return; if (!CloseUnhandledDialogs ) return; //Logger.LogAction("Auto closing dialog with title: '{0}', text: {1}, style: ", window.Title, window.Message, window.StyleInHex); try { window.ForceClose(); } catch (Exception) { } } }
/// <summary> /// Called by the constructor to start watching popups /// on a separate thread. /// </summary> private void Start() { while (_keepRunning) { var mainWindow = new Window(MainWindowHwnd); if (mainWindow.Exists()) { var winEnumerator = new WindowsEnumerator(); var windows = winEnumerator.GetWindows(window => window.ProcessID == mainWindow.ProcessID); foreach (var window in windows) { if (!_keepRunning) return; HandleWindow(new Window(window.Hwnd)); } // Keep DialogWatcher responsive during 1 second sleep period var count = 0; while (_keepRunning && count < 5) { Thread.Sleep(200); count++; } } else { _keepRunning = false; } } }
public bool HandleDialog(Window window) { return false; }
public bool CanHandleDialog(Window window, IntPtr mainWindowHwnd) { lastSeenWindow = window; return false; }
private static bool DialogBelongsToIEWindowForIe7AndLower(Window dialog, Window mainWindow) { return dialog.ToplevelWindow.Equals(mainWindow); }