Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Change size selected window to any width or height

Description
This script will prompt you to enter a width and height in pixels.
Language
C#.net
Minimum Version
Created By
KarolPiechoczek
Contributors
-
Date Created
Mar 23, 2021
Date Last Modified
Mar 23, 2021

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Diagnostics;
using System.Runtime.InteropServices;

public static class DisplayFusionFunction
{
    [DllImport("user32.dll")] static extern int SetWindowText(IntPtr hWnd, string windowName);
    [DllImport("user32.dll", SetLastError = true)] internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr FindWindow(string strClassName, string strWindowName);
    [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
    
    public struct Rect
    {
        public int Left { get; set; }
        public int Top { get; set; }
        public int Right { get; set; }
        public int Bottom { get; set; }
    }
        
	public static void Run(IntPtr windowHandle)
	{
        uint processID = BFS.Application.GetAppIDByWindow(windowHandle);
        Process process = Process.GetProcessById(Convert.ToInt16(processID));
        
        IntPtr ptr = process.MainWindowHandle;
        string size = BFS.Dialog.GetUserInput("Enter the width/height for a new size: ", "");
        Rect rect = new Rect();
        GetWindowRect(ptr, ref rect);
        MoveWindow(process.MainWindowHandle, rect.Left, rect.Top, Convert.ToInt16(size), Convert.ToInt16(size), true);
	}
}