/// <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 IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == uCallBackMsg) { if (wParam.ToInt32() == (int)ABNotify.ABN_FULLSCREENAPP) { IntPtr win = WinAPIWrapper.GetForegroundWindow(); if (!win.Equals(desktopHandle) && !win.Equals(shellHandle) && lParam.ToInt32() == 1) { HideAllView(true); } else { HideAllView(false); } } } return(IntPtr.Zero); }
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); }