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?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

Move all off-screen windows to the current monitor

Description
This script will move all windows that aren't on the current monitor, to the current monitor.
Language
C#.net
Minimum Version
Created By
Christian Treffler
Contributors
-
Date Created
Sep 13, 2021
Date Last Modified
Sep 13, 2021

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
        Rectangle MonRect = BFS.Monitor.GetMonitorBoundsByMouseCursor();

        // Loop through the visible windows and move them to the monitor that has the mouse cursor, if they are not on any monitor
        foreach (IntPtr handle in BFS.Window.GetVisibleWindowHandles())
        {
			Rectangle WinRect = BFS.Window.GetBounds(handle);
			bool moveit = false; 
			uint monitorid = BFS.Monitor.GetMonitorIDByWindow(handle);
			if(monitorid == 0)	// Not on any monitor
			{
				moveit = true;
			}
			else
			{
				Rectangle IntersectSize = Rectangle.Intersect(WinRect, BFS.Monitor.GetMonitorBoundsByID(monitorid));
				if (IntersectSize.Width < 3 || IntersectSize.Height < 3) // Has a monitor, but barely visible
				{
					moveit = true;
				}
			}
			
			if(moveit)
			{
				BFS.DisplayFusion.RunFunctionWithWindowHandle("Move Window to Current Monitor", handle);
				BFS.Window.MoveToCentreMonitor(handle);
				BFS.Window.SetSize(handle, WinRect.Width, WinRect.Height);
			}
        }   
	}
}