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?

Scale Window Size Up/Down

Description
This function quickly increases or decreases the size of the focused window. The amount by which the window is resized is configurable, and the window is automatically constrained (smallest size is user configurable, biggest size is the monitor's dimensions) before being resized.
Language
C#.net
Minimum Version
Created By
Ryan Thaut
Contributors
-
Date Created
Oct 25, 2017
Date Last Modified
Oct 25, 2017

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Collections.Generic;

// 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 the scale amount
        // (greater than 1.0 increases window size, less than 1.0 decreases window size)
        float scaleAmount = 0.9f;

        // set the minimum size for the window (relative to the monitor's size)
        float minimumRelativeSize = 0.2f;

        /* === DO NOT MODIFY BELOW THIS LINE === */

        Rectangle rWindow = BFS.Window.GetBounds(windowHandle);
        Rectangle rMonitor = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);

        int iWinW = (int)(rWindow.Width * scaleAmount);
        int iWinH = (int)(rWindow.Height * scaleAmount);
        int iWinX = rWindow.Left - (int)((iWinW - rWindow.Width) / 2.0f);
        int iWinY = rWindow.Top - (int)((iWinH - rWindow.Height) / 2.0f);

        // constrain the window to the monitor's bounds
        if (iWinW > rMonitor.Width || iWinX < rMonitor.Left || (iWinX + iWinW) > rMonitor.Right)
        {
            iWinW = rWindow.Width;
            iWinX = rWindow.Left;
        }

        if (iWinH > rMonitor.Height || iWinY < rMonitor.Top || (iWinY + iWinH) > rMonitor.Bottom)
        {
            iWinH = rWindow.Height;
            iWinY = rWindow.Top;
        }

        // enforce the minimum size constraint
        if (iWinW < (int)(rMonitor.Width * minimumRelativeSize))
        {
            iWinW = rWindow.Width;
            iWinX = rWindow.Left;
        }

        if (iWinH < (int)(rMonitor.Height * minimumRelativeSize))
        {
            iWinH = rWindow.Height;
            iWinY = rWindow.Top;
        }

        BFS.Window.SetSizeAndLocation(windowHandle, iWinX, iWinY, iWinW, iWinH);
    }
}