Beispiel #1
0
        private bool ListWindowsHandler(IntPtr hWnd, IntPtr lParam)
        {
            _logServices.TraceEnter();
            try
            {
                _logServices.Trace($"Getting process associated with window {hWnd}...");
                var thread  = GetWindowThreadProcessId(hWnd, out uint processId);
                var process = Process.GetProcessById((int)processId);

                _logServices.Trace($"Checking if \"{process.ProcessName}\" is an Office process...");
                switch (process.ProcessName.ToLower())
                {
                case "excel":
                case "winword":

                    break;

                default:
                    _logServices.Trace($"\"{process.ProcessName}\" is not an Office process.  Returning...");

                    return(true);
                }

                // get the text for this window
                var windowText = GetWindowText(hWnd);

                _logServices.Trace($"Checking if \"{windowText}\" is a password window...");
                if (!windowText.EndsWith(" Password"))
                {
                    _logServices.Trace($"\"{windowText}\" is not a password window.  Returning...");
                    return(true);
                }

                _logServices.Trace($"Notifying window...");
                var window = new Models.Window
                {
                    Handle = hWnd,
                    Title  = windowText
                };
                OnUpdate(window);

                return(true);
            }
            catch (Exception ex)
            {
                OnError(ex);

                return(true);
            }
            finally
            {
                _logServices.TraceExit();
            }
        }
Beispiel #2
0
 protected void OnUpdate(Models.Window window)
 {
     _logServices.TraceEnter();
     try
     {
         _logServices.Trace($"Notifying {_observers.Count} observers...");
         foreach (var observer in _observers)
         {
             observer.OnNext(window);
         }
     }
     finally
     {
         _logServices.TraceExit();
     }
 }