Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Cycle Left Through 1/3 Sections

Description
This script will size the window to 1/3 of the screen and cycle left through each section of the screen.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Feb 21, 2019
Date Last Modified
Feb 21, 2019

Scripted Function (Macro) Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
	public static void Run(IntPtr windowHandle)
	{
		// Specify the number of sections to divide the monitor into here
		int numberOfSections = 3;
	
		// Setup the sections
		Rectangle[] sections = GetSections(numberOfSections, BFS.Monitor.GetMonitorIDByWindow(windowHandle));
		
		// Check where the window currently is, then move it appropriately
		foreach (Rectangle section in sections)
		{
            // Check if the window is in this section
            if (BFS.Window.GetBounds(windowHandle) == section)
            {
                // Get the next section index
                int nextSection;
                if (Array.IndexOf(sections, section) > 0)
                {
                    nextSection = Array.IndexOf(sections, section) - 1;
                }
                else
                {
                    // Get the next monitor ID
                    uint[] monitorIDs = BFS.Monitor.GetMonitorIDs();
                    uint nextMonitorID;
                    if (Array.IndexOf(monitorIDs, BFS.Monitor.GetMonitorIDByWindow(windowHandle)) > 0)
                    {
                        nextMonitorID = monitorIDs[Array.IndexOf(monitorIDs, BFS.Monitor.GetMonitorIDByWindow(windowHandle)) - 1];
                    }
                    else
                    {
                        nextMonitorID = monitorIDs[monitorIDs.GetUpperBound(0)];
                    }
                    sections = GetSections(numberOfSections, nextMonitorID);
                    nextSection = sections.GetUpperBound(0);
                }
                
                // Move the window to the next section
                BFS.Window.SetSizeAndLocation(windowHandle, sections[nextSection].X, sections[nextSection].Y, sections[nextSection].Width, sections[nextSection].Height);
                
                // Exit the script
                return;
            }
            else
            {
                // Check the window against the next section
                continue;
            }
		}
		
		// If we get here, the window wasn't in any of the sections, so move it to the first section
        BFS.Window.SetSizeAndLocation(windowHandle, sections[0].X, sections[0].Y, sections[0].Width, sections[0].Height);
	}
	
    private static Rectangle[] GetSections(int numberOfSections, uint monitorID)
    {
        Rectangle monitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorID);
        Rectangle section1 = new Rectangle(monitorWorkArea.X, monitorWorkArea.Y, monitorWorkArea.Width / numberOfSections, monitorWorkArea.Height);
        Rectangle section2 = new Rectangle(monitorWorkArea.X + monitorWorkArea.Width / numberOfSections, monitorWorkArea.Y, monitorWorkArea.Width / numberOfSections, monitorWorkArea.Height);
        Rectangle section3 = new Rectangle(monitorWorkArea.X + ((monitorWorkArea.Width / numberOfSections) * 2), monitorWorkArea.Y, monitorWorkArea.Width / numberOfSections, monitorWorkArea.Height);
        Rectangle[] sections = { section1, section2, section3 };
        return sections;
    }
}