private static bool GetMainWindowForProcess_EnumWindows(List <IntPtr> ptrList, IntPtr hWndEnumerated, uint lParam) { WindowStyleFlags styleCurrentWindowStandard = Native.GetWindowLong(hWndEnumerated, WindowLongIndex.Style); if (lParam == 0) // strict: windows that are visible and have a border { if (Native.IsWindowVisible(hWndEnumerated)) { if ( ((styleCurrentWindowStandard & WindowStyleFlags.Caption) > 0) && ( ((styleCurrentWindowStandard & WindowStyleFlags.Border) > 0) || ((styleCurrentWindowStandard & WindowStyleFlags.ThickFrame) > 0) ) ) { ptrList.Add(hWndEnumerated); } } } else if (lParam == 1) // loose: windows that are visible { if (Native.IsWindowVisible(hWndEnumerated)) { if (((uint)styleCurrentWindowStandard) != 0) { ptrList.Add(hWndEnumerated); } } } return(true); }
private static bool GetMainWindowForProcess_EnumWindows(List <IntPtr> ptrList, IntPtr hWndEnumerated, uint lParam) { var styleCurrentWindowStandard = Native.GetWindowLong(hWndEnumerated, WindowLongIndex.Style); switch (lParam) { case 0: if (Native.IsWindowVisible(hWndEnumerated)) { if ( ((styleCurrentWindowStandard & WindowStyleFlags.Caption) > 0) && ( ((styleCurrentWindowStandard & WindowStyleFlags.Border) > 0) || ((styleCurrentWindowStandard & WindowStyleFlags.ThickFrame) > 0) ) ) { ptrList.Add(hWndEnumerated); } } break; case 1: if (Native.IsWindowVisible(hWndEnumerated)) { if (((uint)styleCurrentWindowStandard) != 0) { ptrList.Add(hWndEnumerated); } } break; } return(true); }
public static void ToggleWindowsTaskbarVisibility(Tools.Boolstate forced = Tools.Boolstate.Indeterminate) { try { IntPtr hTaskBar = Native.FindWindow("Shell_TrayWnd", null); if ((hTaskBar.ToInt32() == Native.INVALID_HANDLE_VALUE) || (hTaskBar == IntPtr.Zero)) { return; } bool TaskBarIsCurrentlyVisible = Native.IsWindowVisible(hTaskBar); bool WantToMakeWindowsTaskbarVisible = (forced == Tools.Boolstate.True) ? true : (forced == Tools.Boolstate.False) ? false : !TaskBarIsCurrentlyVisible; // For forced modes, if the taskbar is already visible and we're requesting to show it, then do nothing if (WantToMakeWindowsTaskbarVisible && TaskBarIsCurrentlyVisible) { return; } // For forced modes, if the taskbar is already hidden and we're requesting to hide it, then do nothing if (!WantToMakeWindowsTaskbarVisible && !TaskBarIsCurrentlyVisible) { return; } // If we're hiding the taskbar, let's take some notes on the original screen desktop work areas if (!WantToMakeWindowsTaskbarVisible) { foreach (Screen screen in Screen.AllScreens) { OriginalScreenInfo osi = new OriginalScreenInfo(); osi.screen = screen; osi.workarea = new Native.Rect(); osi.workarea.Left = screen.WorkingArea.Left; osi.workarea.Top = screen.WorkingArea.Top; osi.workarea.Right = screen.WorkingArea.Right; osi.workarea.Bottom = screen.WorkingArea.Bottom; OriginalScreens.Add(osi); } } // Show or hide the Windows taskbar Native.ShowWindow(hTaskBar, (WantToMakeWindowsTaskbarVisible) ? WindowShowStyle.ShowNoActivate : WindowShowStyle.Hide); // Keep track of the taskbar state so we don't let the user accidentally close Borderless Gaming WindowsTaskbarIsHidden = !WantToMakeWindowsTaskbarVisible; if (WantToMakeWindowsTaskbarVisible) { // If we're showing the taskbar, let's restore the original screen desktop work areas... foreach (OriginalScreenInfo osi in OriginalScreens) { Native.SystemParametersInfo(SPI.SPI_SETWORKAREA, 0, ref osi.workarea, SPIF.SPIF_SENDCHANGE); } // ...and then forget them (we don't need them anymore) OriginalScreens.Clear(); // And we need to redraw the system tray in case tray icons from other applications did something while the // taskbar was hidden. Simulating mouse movement over the system tray seems to be the best way to get this // done. RedrawWindowsSystemTrayArea(); } else { // If we're hiding the taskbar, let's set the screen desktop work area over the entire screen so that // maximizing windows works as expected. foreach (OriginalScreenInfo osi in OriginalScreens) { Native.Rect rect = new Native.Rect(); rect.Left = osi.screen.Bounds.Left; rect.Top = osi.screen.Bounds.Top; rect.Right = osi.screen.Bounds.Right; rect.Bottom = osi.screen.Bounds.Bottom; Native.SystemParametersInfo(SPI.SPI_SETWORKAREA, 0, ref rect, SPIF.SPIF_SENDCHANGE); // Note: WinAPI SystemParametersInfo() will automatically determine which screen by the rectangle we pass in. // (it's not possible to specify which screen we're referring to directly) } } } catch { } }