bool UpdateFocus(IntPtr windowHandle, string windowClassName)
{
if (windowHandle == _focusedWindowHandle)
{
Debug.Assert(_focusedWindowClassName == windowClassName); // I've seen this, with _focusedWindowClassName == "" and windowClassName == "EXCEL7".
return false;
}
Debug.Assert(_focusedWindowClassName != _excelToolTipClass); // We don't expect the ToolTip to ever get the focus
Logger.WindowWatcher.Verbose($"Focus lost by {_focusedWindowHandle} ({_focusedWindowClassName})");
// It has changed - raise an event for the old window
switch (_focusedWindowClassName)
{
case _popupListClass:
PopupListWindowChanged?.Invoke(this, new WindowChangedEventArgs(_focusedWindowHandle, WindowChangedEventArgs.ChangeType.Unfocus));
break;
case _inCellEditClass:
InCellEditWindowChanged?.Invoke(this, new WindowChangedEventArgs(_focusedWindowHandle, WindowChangedEventArgs.ChangeType.Unfocus));
break;
case _formulaBarClass:
FormulaBarWindowChanged?.Invoke(this, new WindowChangedEventArgs(_focusedWindowHandle, WindowChangedEventArgs.ChangeType.Unfocus));
break;
//case _nuiDialogClass:
default:
// Not one of our watched window, so we don't care
break;
}
// Set the new focus info
// Event will be raised by WinEventReceived handler itself
_focusedWindowHandle = windowHandle;
_focusedWindowClassName = windowClassName;
Logger.WindowWatcher.Verbose($"Focus changed to {windowHandle} ({windowClassName})");
return true;
}