Ejemplo n.º 1
0
        // This runs on the Excel main thread - get off quickly
        void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
                            WinEventObjectId idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            try
            {
                if (disposedValue)
                {
                    return;
                }

                if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero)
                {
                    return;
                }

                if (!IsSupportedWinEvent(eventType))
                {
                    return;
                }

                // CONSIDER: We might add some filtering here... maybe only interested in some of the window / event combinations
                _syncContextAuto.Post(OnWinEventReceived, new WinEventArgs(eventType, hWnd, idObject, idChild, dwEventThread, dwmsEventTime));
            }
            catch (Exception ex)
            {
                Logger.WinEvents.Warn($"HandleWinEvent Exception {ex}");
            }
        }
Ejemplo n.º 2
0
        // This runs on the Excel main thread (usually, not always) - get off quickly
        void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
                            WinEventObjectId idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            // Debug.Print($"++++++++++++++ WinEvent Received: {eventType} on thread {Thread.CurrentThread.ManagedThreadId} from thread {dwEventThread} +++++++++++++++++++++++++++");
            try
            {
                if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero)
                {
                    return;
                }

                if (!IsSupportedWinEvent(eventType) || idObject == WinEventObjectId.OBJID_CURSOR || hWnd == IntPtr.Zero)
                {
                    return;
                }

                // Moving the GetClassName call here where the main thread is running.
                var windowClassName = Win32Helper.GetClassName(hWnd);

                if (string.IsNullOrEmpty(windowClassName))
                {
                    return;
                }

                // CONSIDER: We might add some filtering here... maybe only interested in some of the window / event combinations
                _syncContextAuto.Post(OnWinEventReceived, new WinEventArgs(eventType, hWnd, windowClassName, idObject, idChild, dwEventThread, dwmsEventTime));
            }
            catch (Exception ex)
            {
                Logger.WinEvents.Warn($"HandleWinEvent Exception {ex}");
            }
        }
 public WinEventArgs(WinEvent eventType, IntPtr hWnd, WinEventObjectId idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
 {
     EventType     = eventType;
     WindowHandle  = hWnd;
     ObjectId      = idObject;
     ChildId       = idChild;
     EventThreadId = dwEventThread;
     EventTimeMs   = dwmsEventTime;
 }
Ejemplo n.º 4
0
        // This runs on the Excel main thread (usually, not always) - get off quickly
        void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
                            WinEventObjectId idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            // Debug.Print(string.Format("++++++++++++++ WinEvent Received: {eventType} on thread {Thread.CurrentThread.ManagedThreadId} from thread {dwEventThread} +++++++++++++++++++++++++++");
            try
            {
                if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero)
                {
                    return;
                }

                if (!IsSupportedWinEvent(eventType))
                {
                    return;
                }

                // CONSIDER: We might add some filtering here... maybe only interested in some of the window / event combinations
                _syncContextAuto.Post(OnWinEventReceived, new WinEventArgs(eventType, hWnd, idObject, idChild, dwEventThread, dwmsEventTime));
            }
            catch (Exception ex)
            {
                Logger.WinEvents.Warn(string.Format("HandleWinEvent Exception {0}", ex));
            }
        }