{ "name": "Move All Windows to Next Monitor (Keep Z Order)", "language": 0, "code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Drawing;\r\nusing System.Runtime.InteropServices;\r\n\r\n// The 'windowHandle' parameter will contain the window handle for the:\r\n// - Active window when run by hotkey\r\n// - Window Location target when run by a Window Location rule\r\n// - TitleBar Button owner when run by a TitleBar Button\r\n// - Jump List owner when run from a Taskbar Jump List\r\n// - Currently focused window if none of these match\r\npublic static class DisplayFusionFunction\r\n{\r\n\t[DllImport(\"user32.dll\", SetLastError = true)]\r\n\tstatic extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);\r\n\t\r\n\t//some constants\r\n\tconst uint GW_HWNDNEXT = 2;\r\n\t\r\n\tpublic static void Run(IntPtr windowHandle)\r\n\t{ \r\n // Get a list of each visible window on our monitors, and throw them in a HashSet\t\t\r\n HashSet visibleWindows = new HashSet(BFS.Window.GetVisibleAndMinimizedWindowHandles());\r\n \r\n // Make a stack so we can store the z-order of the windows \r\n Stack windows = new Stack();\r\n \r\n // Enumerate through the monitors, starting with the focused window, and moving down\r\n\t\tfor(IntPtr window = BFS.Window.GetFocusedWindow(); ; window = GetWindow(window, GW_HWNDNEXT))\r\n\t\t{\r\n\t\t\t// Check to see if there are any windows left\r\n\t\t\tif(window == IntPtr.Zero)\r\n\t\t\t\tbreak;\r\n\t\t\t\r\n\t\t\t// If it is a window we should ignore, ignore it\r\n\t\t\tif(IsDisplayFusionWindowOrHiddenExplorerWindow(window))\r\n\t\t\t\tcontinue;\r\n\t\t\t\r\n\t\t\t// Check to see if the window exists in either of our hashsets.\r\n\t\t\t// If it does, store it\r\n\t\t\tif(!visibleWindows.Contains(window))\r\n\t\t\t\tcontinue;\r\n\t\t\t\r\n windows.Push(window);\r\n\t\t}\r\n \r\n // Loop through the stack (first in last out) and move the windows\r\n IntPtr lastWindow = IntPtr.Zero;\r\n foreach(IntPtr window in windows)\r\n\t\t{\r\n BFS.Window.MoveToNextMonitor(window);\r\n\t\t\tlastWindow = window;\r\n }\r\n\t\t\r\n // Focus the last window. This should be the top of the z-order\r\n BFS.Window.Focus(lastWindow);\r\n\t}\r\n\t\r\n\tprivate static bool IsDisplayFusionWindowOrHiddenExplorerWindow(IntPtr window)\r\n\t{\r\n // Ignore any DisplayFusion windows (title bar buttons, etc.)\r\n // Ignore pesky hidden explorer.exe windows\r\n string windowClass = BFS.Window.GetClass(window);\r\n if((windowClass.StartsWith(\"DF\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"EdgeUiInputTopWndClass\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"EdgeUiInputWndClass\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"NativeHWNDHost\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"ModeInputWnd\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"MetroGhostWindow\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"ImmersiveLauncher\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"ApplicationManager_ImmersiveShellWindow\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"Shell_TrayWnd\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"WorkerW\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"Progman\", StringComparison.OrdinalIgnoreCase)) ||\r\n (windowClass.Equals(\"SearchPane\", StringComparison.OrdinalIgnoreCase)))\r\n {\r\n return true;\r\n }\r\n \r\n return false;\r\n\t}\r\n}", "description": "", "references": "Microsoft.VisualBasic.Core.dll|Microsoft.Win32.Primitives.dll|Microsoft.Win32.Registry.dll|netstandard.dll|Newtonsoft.Json.dll|System.Collections.Concurrent.dll|System.Collections.dll|System.Collections.Immutable.dll|System.Collections.NonGeneric.dll|System.Collections.Specialized.dll|System.ComponentModel.Primitives.dll|System.ComponentModel.TypeConverter.dll|System.Console.dll|System.Core.dll|System.Data.dll|System.Diagnostics.Process.dll|System.dll|System.Drawing.Common.dll|System.Drawing.dll|System.Drawing.Primitives.dll|System.IO.Compression.dll|System.IO.dll|System.IO.FileSystem.Watcher.dll|System.Linq.dll|System.Linq.Expressions.dll|System.Linq.Parallel.dll|System.Linq.Queryable.dll|System.Management.dll|System.Net.dll|System.Net.Primitives.dll|System.Net.Requests.dll|System.Net.WebClient.dll|System.Net.WebHeaderCollection.dll|System.Private.CoreLib.dll|System.Private.Uri.dll|System.Private.Xml.dll|System.Runtime.dll|System.Runtime.InteropServices.dll|System.Runtime.Serialization.Formatters.dll|System.Security.Cryptography.Algorithms.dll|System.Security.Cryptography.Csp.dll|System.Security.Cryptography.Primitives.dll|System.Text.Json.dll|System.Text.RegularExpressions.dll|System.Threading.dll|System.Threading.Tasks.dll|System.Threading.Tasks.Parallel.dll|System.Web.dll|System.Web.HttpUtility.dll|System.Windows.Forms.dll|System.Windows.Forms.Primitives.dll|System.Xml.dll" }