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?

Get Window Bounds, Size, and Ratio

Description
This script will get the window bounds and size, calculate the width:height ratio, and show the results in a message box.
Language
C#.net
Minimum Version
Created By
Andrew Brink
Contributors
-
Date Created
1d ago
Date Last Modified
1d ago

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
//   - Trigger target when run by a Trigger 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 window dimensions
        Rectangle bounds = BFS.Window.GetBounds(windowHandle);
        
        // Calculate the aspect ratio (height divided by width)
        double ratio = (double)bounds.Height / bounds.Width;
        
        // Format the ratio to show 2 decimal places
        string formattedRatio = ratio.ToString("0.00");
        
        // Create a detailed message with all Rectangle properties and the ratio
        string message = "Window Dimensions\n\n" +
                        "Position: X=" + bounds.X + ", Y=" + bounds.Y + "\n" +
                        "Size: Width=" + bounds.Width + "px, Height=" + bounds.Height + "px\n" +
                        "Height/Width Ratio: " + formattedRatio;
        
        // Display dimensions in a message box
        BFS.Dialog.ShowMessageInfo(message);
    }
}