/// <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)) { IntPtr deskWindow = WinAPIWrapper.GetDesktopWindow(); if (!foreWindow.Equals(deskWindow) && !foreWindow.Equals(WinAPIWrapper.GetShellWindow())) { WinAPIWrapper.GetWindowRect(foreWindow, out RECT foreWindowRECT); WinAPIWrapper.GetWindowRect(deskWindow, out 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; } 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) { } }
private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == uCallBackMsg) { if (wParam.ToInt32() == (int)ABNotify.ABN_FULLSCREENAPP) { bool hasFull = false; if (lParam.ToInt32() == 1) { IntPtr foreWindow = WinAPIWrapper.GetForegroundWindow(); WinAPIWrapper.GetWindowThreadProcessId(foreWindow, out uint processid); String foreGroundWindowName = ""; try { foreGroundWindowName = Process.GetProcessById((int)processid).ProcessName; } catch (Exception) { } if (foreGroundWindowName != "explorer" && !foreWindow.Equals(new WindowInteropHelper(this).Handle)) { IntPtr deskWindow = WinAPIWrapper.GetDesktopWindow(); if (!foreWindow.Equals(deskWindow) && !foreWindow.Equals(WinAPIWrapper.GetShellWindow())) { WinAPIWrapper.GetWindowRect(foreWindow, out RECT foreWindowRECT); WinAPIWrapper.GetWindowRect(deskWindow, out RECT deskWindowRECT); hasFull = foreWindowRECT.left <= deskWindowRECT.left && foreWindowRECT.top <= deskWindowRECT.top && foreWindowRECT.right >= deskWindowRECT.right && foreWindowRECT.bottom >= deskWindowRECT.bottom; } } } HideAllView(hasFull); } } return(IntPtr.Zero); }