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?

Toggle Window Size 100%

Description
This script will toggle the window size between 100% and its previous size.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Dec 21, 2020
Date Last Modified
Dec 21, 2020

Scripted Function (Macro) Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger 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)
	{
        // Get the current size
        Rectangle currentBounds = BFS.Window.GetBounds(windowHandle);
       
        // Get the monitor bounds
        Rectangle monitorBounds = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle);

        if (currentBounds == monitorBounds)
        {
            // Load the settings and set the window size
            string[] savedBounds = BFS.ScriptSettings.ReadValue(windowHandle.ToString()).Split(',');
            Rectangle targetBounds = new Rectangle(Convert.ToInt32(savedBounds[0]),Convert.ToInt32(savedBounds[1]),Convert.ToInt32(savedBounds[2]),Convert.ToInt32(savedBounds[3]));
            BFS.Window.SetSizeAndLocation(windowHandle, targetBounds.X, targetBounds.Y, targetBounds.Width, targetBounds.Height);
        }
		else
		{
            // Save the current size
            BFS.ScriptSettings.WriteValue(windowHandle.ToString(), currentBounds.X.ToString() + "," + currentBounds.Y.ToString() + "," + currentBounds.Width.ToString() + "," + currentBounds.Height.ToString());
            
            // Set it to 100% width/height
            BFS.Window.SetSizeAndLocation(windowHandle, monitorBounds.X, monitorBounds.Y, monitorBounds.Width, monitorBounds.Height);
        }
        
        // Cleanup old saved window sizes
        IntPtr[] allWindows = BFS.Window.GetAllWindowHandles();
        foreach (string valueName in BFS.ScriptSettings.GetValueNames())
        {
            bool windowExists = false;
            foreach (IntPtr window in allWindows)
            {
                if (valueName == window.ToString())
                {
                    windowExists = true;
                    break;
                }
            }
            if (!windowExists)
            {
                BFS.ScriptSettings.DeleteValue(valueName);
            }
        }
    }
}