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?
Save up to 50% on our desktop apps during our Year End Sale!Save up to 50% on our desktop apps during our Year End Sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save up to 50% on our desktop apps during our Year End Sale!

Open Notepad in Position A or B

Description
This script will check if there's an open Notepad in position A (line 15) and if not, it will put it there. If there is one in position A, it will put the new window in Position B (line 16). If there is already a window in position A and B, it will put any subsequent Notepad windows in position A.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Apr 15, 2021
Date Last Modified
Apr 15, 2021

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)
	{
		// Set the X, Y, Width, Height of the two positions here
		Rectangle positionA = new Rectangle(0, 0, 960, 1040);
		Rectangle positionB = new Rectangle(960, 0, 960, 1040);
		
		// Set the process name of the application here
		String processName = "notepad.exe";
		
		// Check if there are any open windows at either position
		bool positionAOccupied = false;
		bool positionBOccupied = false;
		foreach (IntPtr window in BFS.Window.GetVisibleWindowHandles())
		{
            if (BFS.Application.GetMainFileByWindow(window).Contains(processName.ToLower()))
            {
                Rectangle bounds = BFS.Window.GetBounds(window);
                if (bounds == positionA)
                {
                    positionAOccupied = true;
                }
                else if (bounds == positionB)
                {
                    positionBOccupied = true;
                }
            }
		}
		
		// Place the new window depending on where the open ones are
		if (positionAOccupied && !positionBOccupied)
		{
            BFS.Window.SetSizeAndLocation(windowHandle, positionB.X, positionB.Y, positionB.Width, positionB.Height);
		}
		else
		{
            BFS.Window.SetSizeAndLocation(windowHandle, positionA.X, positionA.Y, positionA.Width, positionA.Height);
		}
	}
}