/// <summary> /// Call this method in main thread. /// </summary> /// <param name="causeNotFillScreen">The foreground window is not a full screen App because it doesn't fill the screen. /// Otherwise, because it is Window Explorer or...</param> /// <returns></returns> private bool CheckHasFullScreenApp(out bool causeNotFillScreen) { causeNotFillScreen = false; bool result; IntPtr foreWindow = WinAPIWrapper.GetForegroundWindow(); WinAPIWrapper.GetWindowThreadProcessId(foreWindow, out uint processid); String foreGroundWindowName = ""; try { foreGroundWindowName = Process.GetProcessById((int)processid).ProcessName; //Console.WriteLine("foreGroundWindowName:" + foreGroundWindowName); } catch (Exception) { } if (foreGroundWindowName != "explorer" && !foreWindow.Equals(new WindowInteropHelper(this).Handle))//"SearchUI" { IntPtr deskWindow = WinAPIWrapper.GetDesktopWindow(); if (!foreWindow.Equals(deskWindow) && !foreWindow.Equals(WinAPIWrapper.GetShellWindow())) { WinAPIWrapper.GetWindowRect(foreWindow, out Services.Detail.RECT foreWindowRECT); WinAPIWrapper.GetWindowRect(deskWindow, out Services.Detail.RECT deskWindowRECT); //Console.WriteLine("foreWindow RECT:" + foreWindowRECT); //Console.WriteLine("deskWindow RECT:" + deskWindowRECT); // Check whether foreground Window fills main screen. result = foreWindowRECT.left <= deskWindowRECT.left && foreWindowRECT.top <= deskWindowRECT.top && foreWindowRECT.right >= deskWindowRECT.right && foreWindowRECT.bottom >= deskWindowRECT.bottom; causeNotFillScreen = true; } else { // Foreground Window is DeskWindow or ShellWindow. result = false; } } else { // Foreground window is Windows Explorer or MainWindow itself. result = false; } if (result) { } return(result); }
private static void OnWindowHeightAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { if (d is Window window) { IntPtr handle = new WindowInteropHelper(window).Handle; if (WinAPIWrapper.GetWindowRect(handle, out RECT rect)) { if (PresentationSource.FromVisual(window) != null) { int height = (int)Math.Round(window.PointToScreen(new Point(0, (double)e.NewValue)).Y - rect.top); WinAPIWrapper.SetWindowPos(handle, new IntPtr((int)SpecialWindowHandles.TopMost), rect.left, rect.top, rect.right - rect.left, height, SetWindowPosFlags.SHOWWINDOW); } } } } catch (Exception) { } }