Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Cascade Windows on Current Monitor

Description
This script will cascade all of the windows on the current monitor.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Apr 9, 2020
Date Last Modified
Apr 9, 2020

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
        // Get the current monitor ID
        uint monitorID = BFS.Monitor.GetMonitorIDByXY(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY());
        
        // Get all visible and minimized windows
		IntPtr[] windows = BFS.Window.GetVisibleAndMinimizedWindowHandles();
		
        // Get the monitor bounds
        Rectangle monitorBounds = BFS.Monitor.GetMonitorBoundsByID(monitorID);

		// Set the starting position for the first window in the cascade
		int x = monitorBounds.X;
		int y = monitorBounds.Y;
		
		// Loop through the windows, if they're on the current monitor, cascade them
		foreach (IntPtr window in windows)
		{
            if (BFS.Monitor.GetMonitorIDByWindow(window) == monitorID)
            {
                // Ignore windows that have a blank window title
                if (!(BFS.Window.GetText(window) == ""))
                {
                    // Move the window and size it to 75% width/height
                    BFS.Window.SetSizeAndLocation(window, x, y, Convert.ToInt32(monitorBounds.Width * 0.75), Convert.ToInt32(monitorBounds.Height * 0.75));
                
                    // Increment the x,y values for the next window in the loop
                    x = x + 10;
                    y = y + 10;
                }
            }
		}
	}
}