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?

Confirm

Are you sure?

Toggle Window Between Two Sizes

Description
This function will toggle the window between 70% width/height and 90% width/height. You can customize the percentages by editing the "smallSize" and "largeSize" variables at the top of the script.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
May 1, 2015
Date Last Modified
May 1, 2015

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)
	{
		//set your two sizes here in percentages (i.e. 0.5f is 50% of the monitor)
		float smallSize = 0.7f;
		float largeSize = 0.9f;
		
		//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 the smallSize variable, size the window to the largeSize variable
		//otherwise, size the window to the smallSize variable
		if(IsWithin(windowBounds.Width, (int)(monitorBounds.Width * smallSize), 10))
			BFS.Window.SetSize(windowHandle, (int)(monitorBounds.Width * largeSize), (int)(monitorBounds.Height * largeSize));
		else
			BFS.Window.SetSize(windowHandle, (int)(monitorBounds.Width * smallSize), (int)(monitorBounds.Height * smallSize));
	}
	
	//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));
	}
}