@@ -190,7 +190,9 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
190190 if ( _hWndFilterOrZero != IntPtr . Zero && hWnd != _hWndFilterOrZero )
191191 return ;
192192
193- if ( ! IsSupportedWinEvent ( eventType ) || idObject == WinEventObjectId . OBJID_CURSOR || hWnd == IntPtr . Zero )
193+ if ( ! IsSupportedWinEvent ( eventType , idObject )
194+ || idObject == WinEventObjectId . OBJID_CURSOR
195+ || hWnd == IntPtr . Zero )
194196 return ;
195197
196198 // Moving the GetClassName call here where the main thread is running.
@@ -209,7 +211,7 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
209211 }
210212
211213 // A quick filter that runs on the Excel main thread (or other thread handling the WinEvent)
212- bool IsSupportedWinEvent ( WinEvent winEvent )
214+ bool IsSupportedWinEvent ( WinEvent winEvent , WinEventObjectId idObject )
213215 {
214216 return winEvent == WinEvent . EVENT_OBJECT_CREATE ||
215217 // 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)
219221 winEvent == WinEvent . EVENT_SYSTEM_MOVESIZESTART || // Only for the on-demand hook
220222 winEvent == WinEvent . EVENT_SYSTEM_MOVESIZEEND || // Only for the on-demand hook
221223 winEvent == WinEvent . EVENT_OBJECT_SELECTION || // Only for the PopupList
224+ // NB: Including the next event 'EVENT_OBJECT_LOCATIONCHANGE (0x800B = 32779)' without the check for 'OBJID_CARET'
225+ // will cause the Excel main window to lag when dragging.
226+ // This drag issue seems to have been introduced with an Office update around November 2022.
227+ ( winEvent == WinEvent . EVENT_OBJECT_LOCATIONCHANGE && idObject == WinEventObjectId . OBJID_CARET ) ||
222228 winEvent == WinEvent . EVENT_SYSTEM_CAPTURESTART ;
223229 }
224230
0 commit comments