Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Swap All Windows Between Monitors 1 and 2 then Maximize

Description
This script will swap all windows between monitors 1 and 2, and maximize them on both monitors.
Language
C#.net
Minimum Version
Created By
Crisdavid
Contributors
-
Date Created
Mar 28, 2017
Date Last Modified
Mar 28, 2017

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Windows.Forms;

// 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
{
	public static void Run(IntPtr windowHandle)
	{
		//if the passed window handle doesn't exist, exit the function
		if (windowHandle == IntPtr.Zero)
			return;
        
        //get the open windows for each monitor
        IntPtr[] srcWindowsMonitor2 = BFS.Window.GetVisibleWindowHandlesByMonitor(2);
        IntPtr[] srcWindowsMonitor1 = BFS.Window.GetVisibleWindowHandlesByMonitor(1);
        
		//move all of the windows in the destination monitor to the source monitor
		foreach (IntPtr window in srcWindowsMonitor2)
			BFS.Window.MoveToMonitorMaximized(1, window);

        BFS.General.ThreadWait(1000);
			
		//move all of the windows in the source monitor to the destination monitor
		foreach (IntPtr window in srcWindowsMonitor1)
			BFS.Window.MoveToMonitorMaximized(2, window);
	}
}