void _windowLocationChangeHook_WinEventReceived(object sender, WinEventHook.WinEventArgs winEventArgs)
        {
#if DEBUG
            Logger.WinEvents.Verbose($"{winEventArgs.EventType} - Window {winEventArgs.WindowHandle:X} ({Win32Helper.GetClassName(winEventArgs.WindowHandle)} - Object/Child {winEventArgs.ObjectId} / {winEventArgs.ChildId} - Thread {winEventArgs.EventThreadId} at {winEventArgs.EventTimeMs}");
#endif
            LocationChanged?.Invoke(this, EventArgs.Empty);
        }
        void _windowLocationChangeHook_WinEventReceived(object sender, WinEventHook.WinEventArgs winEventArgs)
        {
#if DEBUG
            //Logger.WinEvents.Verbose(string.Format("{winEventArgs.EventType} - Window {winEventArgs.WindowHandle:X} ({Win32Helper.GetClassName(winEventArgs.WindowHandle)} - Object/Child {winEventArgs.ObjectId} / {winEventArgs.ChildId} - Thread {winEventArgs.EventThreadId} at {winEventArgs.EventTimeMs}");
            Logger.WinEvents.Verbose(string.Format("{0} - Window {1:X} ({2} - Object/Child {3} / {4} - Thread {5} at {6}", winEventArgs.EventType, winEventArgs.WindowHandle, Win32Helper.GetClassName(winEventArgs.WindowHandle), winEventArgs.ObjectId, winEventArgs.ChildId, winEventArgs.EventThreadId, winEventArgs.EventTimeMs));
#endif
            LocationChanged.Invoke(this, EventArgs.Empty);
        }
 void _selectionChangeHook_WinEventReceived(object sender, WinEventHook.WinEventArgs e)
 {
     Logger.WindowWatcher.Verbose(string.Format("PopupList PopupListElementSelectedHandler on thread {0}", Thread.CurrentThread.ManagedThreadId));
     UpdateSelectedItem();
 }
Esempio n. 4
0
        // This runs on the Automation thread, via SyncContextAuto passed in to WinEventHook when we created this WindowWatcher
        // CONSIDER: We would be able to run all the watcher updates from WinEvents, including Location and Selection changes,
        //           but since WinEvents have no hwnd filter, UIAutomation events might be more efficient.
        // CONSIDER: Performance optimisation would keep a list of window handles we know about, preventing the class name check every time
        void _windowStateChangeHook_WinEventReceived(object sender, WinEventHook.WinEventArgs e)
        {
            var className = Win32Helper.GetClassName(e.WindowHandle);

            if (e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_FOCUS)
            {
                // Might raise change event for Unfocus
                if (!UpdateFocus(e.WindowHandle, className))
                {
                    // We already have the right focus
                    return;
                }
            }

            // Debug.Print("### Thread receiving WindowStateChange: " + Thread.CurrentThread.ManagedThreadId);
            switch (className)
            {
            //case _sheetWindowClass:
            //    if (e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_SHOW)
            //    {
            //        // Maybe a new workbook is on top...
            //        // Note that there is also an EVENT_OBJECT_PARENTCHANGE (which we are not subscribing to at the moment
            //    }
            //    break;
            case _popupListClass:
                PopupListWindowChanged?.Invoke(this, new WindowChangedEventArgs(e.WindowHandle, e.EventType, e.ObjectId));
                break;

            case _inCellEditClass:
                InCellEditWindowChanged?.Invoke(this, new WindowChangedEventArgs(e.WindowHandle, e.EventType, e.ObjectId));
                break;

            case _formulaBarClass:
                FormulaBarWindowChanged?.Invoke(this, new WindowChangedEventArgs(e.WindowHandle, e.EventType, e.ObjectId));
                break;

            case _excelToolTipClass:
                ExcelToolTipWindowChanged?.Invoke(this, new WindowChangedEventArgs(e.WindowHandle, e.EventType, e.ObjectId));
                break;

            //case _nuiDialogClass:
            //    // Debug.Print($"SelectDataSource {_selectDataSourceClass} Window update: {e.WindowHandle:X}, EventType: {e.EventType}, idChild: {e.ChildId}");
            //    if (e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_CREATE)
            //    {
            //        // Get the name of this window - maybe ours or some other NUIDialog
            //        var windowTitle = Win32Helper.GetText(e.WindowHandle);
            //        if (windowTitle.Equals(_selectDataSourceTitle, StringComparison.OrdinalIgnoreCase))
            //        {
            //            SelectDataSourceWindow = e.WindowHandle;
            //            SelectDataSourceWindowChanged?.Invoke(this,
            //                new WindowChangedEventArgs { Type = WindowChangedEventArgs.ChangeType.Create });
            //        }
            //    }
            //    else if (SelectDataSourceWindow == e.WindowHandle && e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_SHOW)
            //    {
            //        IsSelectDataSourceWindowVisible = true;
            //        SelectDataSourceWindowChanged?.Invoke(this,
            //                new WindowChangedEventArgs { Type = WindowChangedEventArgs.ChangeType.Create });
            //    }
            //    else if (SelectDataSourceWindow == e.WindowHandle && e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_HIDE)
            //    {
            //        IsSelectDataSourceWindowVisible = false;
            //        SelectDataSourceWindowChanged?.Invoke(this, new WindowChangedEventArgs { Type = WindowChangedEventArgs.ChangeType.Hide });
            //    }
            //    else if (SelectDataSourceWindow == e.WindowHandle && e.EventType == WinEventHook.WinEvent.EVENT_OBJECT_DESTROY)
            //    {
            //        IsSelectDataSourceWindowVisible = false;
            //        SelectDataSourceWindow = IntPtr.Zero;
            //        SelectDataSourceWindowChanged?.Invoke(this, new WindowChangedEventArgs { Type = WindowChangedEventArgs.ChangeType.Destroy });
            //    }
            //    break;
            default:
                //InCellEditWindowChanged(this, EventArgs.Empty);
                break;
            }
        }