using System;
using System.Drawing;
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
// Get the window's current bounds
Rectangle currentWindowBounds = BFS.Window.GetBounds(windowHandle);
// Set the window width percentage here
decimal windowWidthPercent = 0.66m;
// Get the monitor bounds
Rectangle monitorBounds = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);
// Create the target window bounds
Rectangle targetWindowBounds = new Rectangle();
// Set the target window width to the screen width * the windowWidthPercent
targetWindowBounds.Width = Convert.ToInt32(monitorBounds.Width * windowWidthPercent);
// Set the target window height to 100% of the screen height
targetWindowBounds.Height = monitorBounds.Height;
// Set the target X value to the left side of the monitor
targetWindowBounds.X = monitorBounds.X;
// Set the target Y value to the top side of the monitor
targetWindowBounds.Y = monitorBounds.Y;
// Move the window to the target location or back to its original location
if ((currentWindowBounds.X <= (targetWindowBounds.X - 15) || (currentWindowBounds.X >= (targetWindowBounds.X - 15))) &&
(currentWindowBounds.Y <= (targetWindowBounds.Y - 15) || (currentWindowBounds.Y >= (targetWindowBounds.Y - 15))) &&
currentWindowBounds.Width == targetWindowBounds.Width &&
currentWindowBounds.Height == targetWindowBounds.Height)
{
// Move it to its original location
BFS.Window.SetSizeAndLocation(windowHandle, Convert.ToInt32(BFS.ScriptSettings.ReadValue(windowHandle.ToString("X8") + "_X")),
Convert.ToInt32(BFS.ScriptSettings.ReadValue(windowHandle.ToString("X8") + "_Y")),
Convert.ToInt32(BFS.ScriptSettings.ReadValue(windowHandle.ToString("X8") + "_Width")),
Convert.ToInt32(BFS.ScriptSettings.ReadValue(windowHandle.ToString("X8") + "_Height")));
// Clear the previously saved bounds
BFS.ScriptSettings.DeleteValue(windowHandle.ToString("X8") + "_X");
BFS.ScriptSettings.DeleteValue(windowHandle.ToString("X8") + "_Y");
BFS.ScriptSettings.DeleteValue(windowHandle.ToString("X8") + "_Width");
BFS.ScriptSettings.DeleteValue(windowHandle.ToString("X8") + "_Height");
}
else
{
// Save the window's current bounds
BFS.ScriptSettings.WriteValue(windowHandle.ToString("X8") + "_X", currentWindowBounds.X.ToString());
BFS.ScriptSettings.WriteValue(windowHandle.ToString("X8") + "_Y", currentWindowBounds.Y.ToString());
BFS.ScriptSettings.WriteValue(windowHandle.ToString("X8") + "_Width", currentWindowBounds.Width.ToString());
BFS.ScriptSettings.WriteValue(windowHandle.ToString("X8") + "_Height", currentWindowBounds.Height.ToString());
// Move the window to the target location
BFS.Window.SetSizeAndLocation(windowHandle, targetWindowBounds.X, targetWindowBounds.Y, targetWindowBounds.Width, targetWindowBounds.Height);
}
// Clean up saved bounds for windows that no longer exist
foreach (string valueName in BFS.ScriptSettings.GetValueNames())
{
IntPtr[] windowHandles = BFS.Window.GetVisibleAndMinimizedWindowHandles();
bool windowStillExists = false;
foreach (IntPtr window in windowHandles)
{
if (valueName.Contains(window.ToString("X8")))
{
windowStillExists = true;
}
}
if (!windowStillExists)
{
BFS.ScriptSettings.DeleteValue(valueName);
}
}
}
}