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?

Rollup window when not in focus

Description
This script will roll up the specified window when not in focus. Set the window text you want to look for on line 15.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Jul 2, 2021
Date Last Modified
Jul 2, 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 part of the Window Text to look for in the window title here
        string targetWindowText = "*Notepad*";
        
        // Loop forever
		while (true)
		{
            // Get the focused window and the target window
            IntPtr focusedWindow = BFS.Window.GetFocusedWindow();
            IntPtr targetWindow = BFS.Window.GetWindowByText(targetWindowText);
            
            // If the target window isn't focused and isn't already rolled up, roll it up
            if (focusedWindow != targetWindow && !BFS.Window.IsWindowRolledUpToIcon(targetWindow))
            {
                BFS.Window.RollupWindowToIcon(targetWindow);
            }
            
            // Wait 250ms before looping to avoid running up the CPU
            BFS.General.ThreadWait(250);
		}
	}
}