/// <summary> /// Detect programs that appear on secondary screen and move them back to primary taskbar /// </summary> public void MoveProgramsToPrimary(bool useCached = false) { if (!useCached) { bool succ = Native.EnumWindows(new Native.EnumDelegate(delegate(IntPtr hwnd, int lParam) { if (Native.IsAltTabVisible(hwnd)) { Win32Window window = Win32Window.FromHandle(hwnd); Screen s = window.Screen; if (!s.Primary) { if (window.Title.Length > 0) { AddTab(window.Handle.ToInt32()); } } } return(true); }), IntPtr.Zero); } else { CachedProcesses.ForEach(delegate(SecondDisplayProcess p) { MoveProgramToPrimary(p); }); } }
public void MinimizeAllFromScreen(Screen screen) { List <SecondDisplayProcess> list; if (!_minimizedByButton.TryGetValue(screen, out list)) { list = new List <SecondDisplayProcess>(); _minimizedByButton.Add(screen, list); } if (CachedProcesses.Any(sp => sp.Screen.Equals(screen) && !sp.IsMinimized)) { list.Clear(); CachedProcesses.ForEach(delegate(SecondDisplayProcess p) { if (!p.IsMinimized) { if (!p.Screen.Equals(screen)) { return; } try { p.Minimize(); } catch { } list.Add(p); } }); } else { if (list.Count == 0) { CachedProcesses.ForEach(delegate(SecondDisplayProcess p) { if (!p.Screen.Equals(screen)) { return; } try { p.Restore(); } catch { } }); } else { list.ForEach(delegate(SecondDisplayProcess p) { try { p.Restore(); } catch { } }); list.Clear(); } } }