Skip to content

Commit

Permalink
Shortcut some WinEvent cases where the window is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
govert committed Oct 29, 2020
1 parent 74b7bd9 commit 6cc15ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
if (_hWndFilterOrZero != IntPtr.Zero && hWnd != _hWndFilterOrZero)
return;

if (!IsSupportedWinEvent(eventType) || idObject == WinEventObjectId.OBJID_CURSOR)
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));
Expand Down
1 change: 1 addition & 0 deletions Source/ExcelDna.IntelliSense/Win32Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public static string GetClassName(IntPtr hWnd)
// It failed!?
int error = Marshal.GetLastWin32Error();
Debug.Print($"GetClassName failed on {hWnd}(0x{hWnd:x}) - Error {error}");
return "";
}
return _buffer.ToString();
}
Expand Down

0 comments on commit 6cc15ad

Please sign in to comment.