diff --git a/Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs b/Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs index 24b1652..03ebac5 100644 --- a/Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs +++ b/Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs @@ -190,7 +190,9 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero) return; - if (!IsSupportedWinEvent(eventType) || idObject == WinEventObjectId.OBJID_CURSOR || hWnd == IntPtr.Zero) + if (!IsSupportedWinEvent(eventType, idObject) + || idObject == WinEventObjectId.OBJID_CURSOR + || hWnd == IntPtr.Zero) return; // Moving the GetClassName call here where the main thread is running. @@ -209,7 +211,7 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, } // A quick filter that runs on the Excel main thread (or other thread handling the WinEvent) - bool IsSupportedWinEvent(WinEvent winEvent) + bool IsSupportedWinEvent(WinEvent winEvent, WinEventObjectId idObject) { return winEvent == WinEvent.EVENT_OBJECT_CREATE || // winEvent == WinEvent.EVENT_OBJECT_DESTROY || // Stopped watching for this, because we can't route using the ClassName and don't really need anymore @@ -219,6 +221,10 @@ bool IsSupportedWinEvent(WinEvent winEvent) winEvent == WinEvent.EVENT_SYSTEM_MOVESIZESTART || // Only for the on-demand hook winEvent == WinEvent.EVENT_SYSTEM_MOVESIZEEND || // Only for the on-demand hook winEvent == WinEvent.EVENT_OBJECT_SELECTION || // Only for the PopupList + // NB: Including the next event 'EVENT_OBJECT_LOCATIONCHANGE (0x800B = 32779)' without the check for 'OBJID_CARET' + // will cause the Excel main window to lag when dragging. + // This drag issue seems to have been introduced with an Office update around November 2022. + (winEvent == WinEvent.EVENT_OBJECT_LOCATIONCHANGE && idObject == WinEventObjectId.OBJID_CARET) || winEvent == WinEvent.EVENT_SYSTEM_CAPTURESTART; } diff --git a/Source/ExcelDna.IntelliSense/UIMonitor/WindowWatcher.cs b/Source/ExcelDna.IntelliSense/UIMonitor/WindowWatcher.cs index a8bfca7..56d6138 100644 --- a/Source/ExcelDna.IntelliSense/UIMonitor/WindowWatcher.cs +++ b/Source/ExcelDna.IntelliSense/UIMonitor/WindowWatcher.cs @@ -69,6 +69,7 @@ internal WindowChangedEventArgs(IntPtr windowHandle, WinEventHook.WinEvent winEv case WinEventHook.WinEvent.EVENT_OBJECT_FOCUS: Type = ChangeType.Focus; break; + case WinEventHook.WinEvent.EVENT_OBJECT_LOCATIONCHANGE: case WinEventHook.WinEvent.EVENT_SYSTEM_MOVESIZEEND: Type = ChangeType.LocationChange; break; @@ -151,9 +152,7 @@ public WindowWatcher(SynchronizationContext syncContextAuto, SynchronizationCont // EVENT_OBJECT_SELECTIONREMOVE // EVENT_OBJECT_SELECTIONWITHIN // EVENT_OBJECT_STATECHANGE (0x800A = 32778) - // NB: Including the next event 'EVENT_OBJECT_LOCATIONCHANGE (0x800B = 32779)' will cause the Excel main window to lag when dragging. - // This drag issue seems to have been introduced with an Office update around November 2022. - _windowStateChangeHooks.Add(new WinEventHook(WinEventHook.WinEvent.EVENT_OBJECT_CREATE, WinEventHook.WinEvent.EVENT_OBJECT_STATECHANGE, syncContextAuto, syncContextMain, IntPtr.Zero)); + _windowStateChangeHooks.Add(new WinEventHook(WinEventHook.WinEvent.EVENT_OBJECT_CREATE, WinEventHook.WinEvent.EVENT_OBJECT_LOCATIONCHANGE, syncContextAuto, syncContextMain, IntPtr.Zero)); _windowStateChangeHooks.Add(new WinEventHook(WinEventHook.WinEvent.EVENT_SYSTEM_CAPTURESTART, WinEventHook.WinEvent.EVENT_SYSTEM_CAPTURESTART, syncContextAuto, syncContextMain, IntPtr.Zero)); foreach (var windowStateChangeHook in _windowStateChangeHooks)