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?

Open Chrome windows on 2 different monitors

Description
This script will open two new Chrome windows in the locations you specify in the script.
Language
C#.net
Minimum Version
Created By
Natsu92385
Contributors
-
Date Created
3d ago
Date Last Modified
3d ago

Scripted Function (Macro) Code

using System;
using System.Diagnostics;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        string chromePath = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
        IntPtr myWorkWindow = BFS.Window.GetFocusedWindow();

        // 1. WINDOW: Monitor 1 (Primary)
        Process.Start(chromePath, "--new-window");
        IntPtr win1 = WaitForNewWindow(myWorkWindow);
        
        if (win1 != IntPtr.Zero)
        {
            BFS.Window.MoveToMonitor(1, win1);
            BFS.Window.Maximize(win1);
            BFS.Window.Focus(win1);
        }

        // Delay to allow Chrome to stabilize
        BFS.General.ThreadWait(2000);

        // 2. WINDOW: Monitor 2 (Secondary / Ultra-Wide)
        Process.Start(chromePath, "--new-window");
        // We ignore win1 to ensure we capture the second new window
        IntPtr win2 = WaitForNewWindow(win1);
        
        if (win2 != IntPtr.Zero && win2 != win1)
        {
            BFS.Window.MoveToMonitor(2, win2);
            BFS.Window.Restore(win2);
            // Set your preferred size here (Width, Height)
            BFS.Window.SetSize(win2, 2560, 1300);
            BFS.Window.SetLocation(win2, 0, 0);
            BFS.Window.Focus(win2);
        }
    }

    private static IntPtr WaitForNewWindow(IntPtr ignore)
    {
        for (int i = 0; i < 20; i++)
        {
            BFS.General.ThreadWait(400);
            IntPtr current = BFS.Window.GetFocusedWindow();
            
            if (current != IntPtr.Zero && current != ignore)
            {
                if (BFS.Window.GetText(current).Length > 0)
                {
                    return current;
                }
            }
        }
        return IntPtr.Zero;
    }
}