Processing Ajax...

Close Dialog


Close Dialog

Close Dialog

A recent AVG and Avast antivirus update is preventing DisplayFusion 9.9 from launching on some systems.
If you're running into this issue, please update to the latest DisplayFusion 10.0 Beta.

Toggle Window Size Between 100% and Previous Size

If the window is not currently 100% height and width, this script will save it's size values, and then make it 100% height and width. If it's already 100% height and width, it will return it to its previous size.
Minimum Version
Created By
Thomas Malloch (BFS)
Date Created
Dec 19, 2014
Date Last Modified
Dec 19, 2014

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
//   - Window Location target when run by a Window Location 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
	private static string WindowSizeSettingsKey = "ToggleWindowSizeSettings";
	public static void Run(IntPtr windowHandle)
		//get the bounds of the window and the monitor it is in
		Rectangle monitorBounds = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);
		Rectangle windowBounds = BFS.Window.GetBounds(windowHandle);
		if((windowBounds.Width == monitorBounds.Width) && (windowBounds.Height == monitorBounds.Height))
			//if the window is the size of the monitor, load settings and restore
			//load the settings
			IntPtr oldWindow;
			Rectangle oldBounds;
			LoadSettings(out oldWindow, out oldBounds);
			//check to see if the settings were loaded properly
			if(oldWindow == IntPtr.Zero)
			//if it isn't the same window, exit
			if(windowHandle.ToInt64() != oldWindow.ToInt64())
			//restore the window position
			BFS.Window.SetSizeAndLocation(windowHandle, oldBounds.X, oldBounds.Y, oldBounds.Width, oldBounds.Height);
			//if the window is smaller than the monitor, save settings
			SaveSettings(windowHandle, windowBounds);
			//make the window the size of the monitor it is in
			BFS.Window.SetSizeAndLocation(windowHandle, monitorBounds.X, monitorBounds.Y, monitorBounds.Width, monitorBounds.Height);
	//this function loads settings that we have previously stored
	private static void LoadSettings(out IntPtr oldWindow, out Rectangle oldBounds)
		//try and load settings
			//split up the settings string into its seperate values
			string[] settings = BFS.ScriptSettings.ReadValue(WindowSizeSettingsKey).Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
			//set the parameters to their default values
			oldWindow = IntPtr.Zero;
			oldBounds = new Rectangle();
			//check to see if we have enough parameters saved to the setting
			if(settings.Length != 5)
				throw new Exception("Incorrect settings format");
			//set the values
			oldWindow = new IntPtr(Convert.ToInt64(settings[0]));
			oldBounds = new Rectangle(
		catch(Exception ex)
			//if we encountered an error, make sure the parameters are set to the default values
			oldWindow = IntPtr.Zero;
			oldBounds = new Rectangle();
	//this function saves settings
	private static void SaveSettings(IntPtr window, Rectangle bounds)
		//make the setting string
		string settings = string.Format("{0}|{1}|{2}|{3}|{4}", window.ToInt64(), bounds.X, bounds.Y, bounds.Width, bounds.Height);
		//save the setting
		BFS.ScriptSettings.WriteValue(WindowSizeSettingsKey, settings);