private void PollingTimer_Elapsed(object sender, ElapsedEventArgs e) { var windowPlacement = User32.GetWindowPlacement(windowHandle); WindowState newWindowState; switch (windowPlacement.showCmd) { case User32.ShowWindowType.SW_MAXIMIZE: newWindowState = WindowState.Maximized; break; case User32.ShowWindowType.SW_HIDE: case User32.ShowWindowType.SW_SHOWMINNOACTIVE: case User32.ShowWindowType.SW_MINIMIZE: case User32.ShowWindowType.SW_SHOWMINIMIZED: newWindowState = WindowState.Minimized; break; case User32.ShowWindowType.SW_NORMAL: default: newWindowState = WindowState.Normal; break; } if (newWindowState != windowState) { windowState = newWindowState; if (windowState != null) { WindowStateChange?.Invoke(this, new WindowStateChangeEventArgs(windowState ?? WindowState.Normal)); } } }
private void OnVisualStateChange(object sender, AutomationPropertyChangedEventArgs e) { WindowVisualState visualState = WindowVisualState.Normal; try { visualState = (WindowVisualState)e.NewValue; } catch (InvalidCastException) { // ignore } WindowStateChange?.Invoke(this, new WindowStateChangeEventArgs((WindowState)visualState)); }