Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Shrink restored when nearly maximum size

Description
This script will reduce the size of the window if it's nearly the full size of the screen but not actually maximized. It can be automated if run from a Trigger rule that uses the "Restore Window" Trigger Event.
Language
C#.net
Minimum Version
Created By
Charles7
Contributors
-
Date Created
Jul 8, 2019
Date Last Modified
Jul 22, 2019

Scripted Function (Macro) Code

using System;
using System.Drawing;

// 20190720 ckx
// Shrink restored when nearly maximum size  (trigger on window restored).
// Use with trigger:
//     1) On window restored
//     2) Window title <blank>
//     3) Add this script to run
public static class DisplayFusionFunction
{
    public static void Run(IntPtr ha)
    {

        // set the scale amount
        // (greater than 1.0 increases window size, less than 1.0 decreases window size)
        float scaleAmount = 0.7f;

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

        /* === DO NOT MODIFY BELOW THIS LINE === */
        
        if(BFS.Window.IsMaximized(ha))
            return;

        Rectangle wbr  = BFS.Window.GetBounds(ha);
        Rectangle mbr  = BFS.Monitor.GetMonitorBoundsByWindow(ha);    

        int dxd = Math.Abs( wbr.Width - mbr.Width );
        int dyd = Math.Abs( wbr.Height - mbr.Height );

        // ShoCoo(wbr,mbr,dxd,dyd);
        
        if ( dxd > (int)(wbr.Width * minimumRelativeSize) )
            return;
        
        if (dyd > (int)(wbr.Height * minimumRelativeSize))
            return;
        
        int fxd = (int)(wbr.Width  * scaleAmount);
        int fyd = (int)(wbr.Height * scaleAmount);
        int fxp = (int)(mbr.X + (wbr.Width  - fxd) / 2) ;
        int fyp = (int)(mbr.Y + (wbr.Height - fyd) / 2) ;        
        BFS.Window.SetSizeAndLocation(ha, fxp, fyp, fxd, fyd );
        
    }
 
}