public bool TryPassword(IntPtr windowHandle, string password) { _logServices.TraceEnter(); try { // find the password window var passwordHandle = FindWindowEx(windowHandle, IntPtr.Zero, "EDIT", null); if (passwordHandle == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // send the password to the text box SendMessage(passwordHandle, WM_SETTEXT, IntPtr.Zero, password); // find the OK button var okHandle = FindWindowEx(windowHandle, IntPtr.Zero, "BUTTON", "OK"); // click the OK button ClickButton(okHandle, 10, 10); // give Excel time to response System.Threading.Thread.Sleep(50); // has the window disappeared? if (!IsWindowVisible(windowHandle)) { return(true); } // get the process id for this window GetWindowThreadProcessId(windowHandle, out int processId); // click the OK button on the new window _windowFinderException = null; foreach (ProcessThread thread in Process.GetProcessById(processId).Threads) { _windowFinder.Find(thread.Id); } // if an Exception was thrown, bubble it up if (_windowFinderException != null) { throw _windowFinderException; } // give the window time to close System.Threading.Thread.Sleep(10); return(false); } finally { _logServices.TraceExit(); } }
private bool FindWindowHandler(IntPtr hWnd, IntPtr lParam) { _logServices.TraceEnter(); try { // get the text for this window var windowText = GetWindowText(hWnd); // save the details of the found window OnUpdate(new Models.Window { Handle = hWnd, Title = windowText }); return(true); } catch (Exception ex) { OnError(ex); return(true); } finally { _logServices.TraceExit(); } }
public void StartWatching() { _logServices.TraceEnter(); try { _logServices.Trace("Adding event handlers..."); _keyboardMouseEvents.MouseClick += MouseUpExtHandler; } finally { _logServices.TraceExit(); } }