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.

Cycle Through Window Sizes

This script switches between 70% and 50% size for the active window.
Minimum Version
Created By
Thomas Malloch (BFS)
Date Created
Dec 30, 2014
Date Last Modified
Dec 30, 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
	public static void Run(IntPtr windowHandle)
		//get the bounds of the current window
		Rectangle windowBounds = BFS.Window.GetBounds(windowHandle);
		//get the bounds of the current monitor
		Rectangle monitorBounds = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);
		//if the window is close in size to 50%, size the window to 70%
		//otherwise, size the window to 50%
		if(IsWithin(windowBounds.Width, (int)(monitorBounds.Width * 0.5f), 10))
			BFS.Window.SetSizeAndLocation(windowHandle, monitorBounds.Left, monitorBounds.Top, (int)(monitorBounds.Width * 0.7f), monitorBounds.Height);
			BFS.Window.SetSizeAndLocation(windowHandle, monitorBounds.Left, monitorBounds.Top, (int)(monitorBounds.Width * 0.5f), monitorBounds.Height);
	//this function returns true if a value is close to another value
	private static bool IsWithin(int value, int target, int threshold)
		return (value == target) || ((value >= target - threshold) && (value <= target + threshold));