using System; using System.Drawing; // The 'windowHandle' parameter will contain the window handle for the: // - Active window when run by hotkey // - Window Location target when run by a Window Location rule // - TitleBar Button owner when run by a TitleBar Button // - Jump List owner when run from a Taskbar Jump List // - Currently focused window if none of these match public static class DisplayFusionFunction { const string WindowProperty_OriginalMonitor = "WindowProperty_OriginalMonitor"; public static void Run(IntPtr windowHandle) { //change these variables to make this script work with your environment //note: the @ in front of the string literal will allow you to use the \ character without having to escape it string gameApplicationPath = @"[the path to the game you would like to wait for]"; string applicationPath = @"[your application path]"; uint monitorId = 3; //wait for the game's application to start while(!BFS.Application.IsAppRunningByFile(gameApplicationPath)) BFS.General.ThreadWait(500); //search through all windows for the application we're looking for and move them to the specified monitor foreach(IntPtr window in BFS.Window.GetAllWindowHandles()) { //ignore any DisplayFusion windows if(BFS.Window.GetClass(window).StartsWith("DF", StringComparison.OrdinalIgnoreCase)) continue; //if this window doesn't belong to the specified application, ignore it if(!BFS.Application.GetMainFileByWindow(window).Equals(applicationPath, StringComparison.OrdinalIgnoreCase)) continue; //set a window property on the window to save it's original monitor BFS.Window.SetWindowProperty(window, WindowProperty_OriginalMonitor, new IntPtr(BFS.Monitor.GetMonitorIDByWindow(window))); //move the window to the specified monitor BFS.Window.MoveToMonitor(monitorId, window); } //wait for the game to close BFS.Application.WaitForExitByFile(gameApplicationPath); foreach(IntPtr window in BFS.Window.GetAllWindowHandles()) { //ignore any DisplayFusion windows if(BFS.Window.GetClass(window).StartsWith("DF", StringComparison.OrdinalIgnoreCase)) continue; //if this isn't the monitor that we moved windows to, ignore it //this way we can ignore windows that were moved after the first part of the script ran if(BFS.Monitor.GetMonitorIDByWindow(window) != monitorId) continue; //try to get the saved monitor ID IntPtr originalMonitorId = BFS.Window.GetWindowProperty(window, WindowProperty_OriginalMonitor); //if we couldn't get a monitor ID, ignore this window if(originalMonitorId == IntPtr.Zero) continue; //move the window back to it's original monitor BFS.Window.MoveToMonitor((uint)originalMonitorId.ToInt64(), window); } } }