Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Swap All Windows Between Monitors 1 and 2

Description
This script will swap all open windows between monitors 1 and 2.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Feb 24, 2017
Date Last Modified
Dec 14, 2018

Scripted Function (Macro) Code

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

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
    	// set the monitor IDs of the  monitors you want to swap here
        uint monitorA = 1;
        uint monitorB = 2;
    
		//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(monitorB);
        IntPtr[] srcWindowsMonitor1 = BFS.Window.GetVisibleWindowHandlesByMonitor(monitorA);
        
		//move all of the windows in the destination monitor to the source monitor
		foreach (IntPtr window in srcWindowsMonitor2)
		{
            if (BFS.Window.GetText(window).Contains("Chrome"))
            {
                BFS.Window.Restore(window);
                BFS.Window.MoveToMonitor(monitorA, window);
                BFS.Window.Maximize(window);
            }
			BFS.Window.MoveToMonitor(monitorA, window);
        }

        BFS.General.ThreadWait(1000);
			
		//move all of the windows in the source monitor to the destination monitor
		foreach (IntPtr window in srcWindowsMonitor1)
        {
            if (BFS.Window.GetText(window).Contains("Chrome"))
            {
                BFS.Window.Restore(window);
                BFS.Window.MoveToMonitor(monitorB, window);
                BFS.Window.Maximize(window);
            }
			BFS.Window.MoveToMonitor(monitorB, window);
        }
	}
}