Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Swap All Windows Between Two Monitors

Description
This function will prompt you to select two monitors. It will then swap all open windows between those two monitors.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Apr 9, 2015
Date Last Modified
Apr 9, 2015

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 source monitor id
		BFS.Dialog.ShowMessageInfo("Please choose the first monitor in the monitor selector that will pop-up next.");
		uint monitorSrc = BFS.Monitor.ShowMonitorSelector();
		
		//get the destination monitor id
		BFS.Dialog.ShowMessageInfo("Please choose the second monitor in the monitor selector that will pop-up next.");
		uint monitorDest = BFS.Monitor.ShowMonitorSelector();
		
		//store all of the window handles in the source monitor
		IntPtr[] srcWindows = BFS.Window.GetVisibleWindowHandlesByMonitor(monitorSrc);
		
		//move all of the windows in the destination monitor to the source monitor
		foreach (IntPtr window in BFS.Window.GetVisibleWindowHandlesByMonitor(monitorDest))
			BFS.Window.MoveToMonitor(monitorSrc, window);
			
		//move all of the windows in the source monitor to the destination monitor
		foreach (IntPtr window in srcWindows)
			BFS.Window.MoveToMonitor(monitorDest, window);
	}
}