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?

Minimize Windows on Current Monitor

Description
This script will minimize all of the windows on the current monitor.
Language
C#.net
Minimum Version
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Mar 6, 2020
Date Last Modified
Oct 20, 2021

Scripted Function (Macro) Code

using System;
using System.Drawing;
 
public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
		// Get the monitor ID based on the mouse position
        uint monitorId = BFS.Monitor.GetMonitorIDByXY(
                         BFS.Input.GetMousePositionX(),
                         BFS.Input.GetMousePositionY());
        
		// Get the visible windows on this monitor
		foreach(IntPtr window in BFS.Window.GetVisibleWindowHandlesByMonitor(monitorId))
        {
			// Check if it's an excluded window (see the list in the IsProtected function below)
            if(IsProtected(window))
                continue;
			
			// If it's not, minimize it
            BFS.Window.Minimize(window);
        }
    }
 
    private static bool IsProtected(IntPtr window)
    {
        if ((BFS.Window.GetText(window).IndexOf("• DisplayFusion", 0, StringComparison.OrdinalIgnoreCase) != -1) ||
            (BFS.Window.HasWindowStyle(BFS.WindowEnum.WindowStyle.WS_MINIMIZEBOX, window).Equals(false)) ||
            //(BFS.Window.HasWindowStyleEx(BFS.WindowEnum.WindowStyleEx.WS_EX_APPWINDOW, window).Equals(true)) ||
            (BFS.Window.GetAlwaysOnTop(window).Equals(true)) ||
            //(BFS.Window.GetClass(window).StartsWith("WindowsForms10", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("EdgeUiInputTopWndClass", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("EdgeUiInputWndClass", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("NativeHWNDHost", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("ModeInputWnd", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("MetroGhostWindow", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("ImmersiveLauncher", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("ApplicationManager_ImmersiveShellWindow", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("Shell_TrayWnd", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("WorkerW", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("Progman", StringComparison.OrdinalIgnoreCase)) ||
            (BFS.Window.GetClass(window).Equals("SearchPane", StringComparison.OrdinalIgnoreCase))
            )
		{
            return true;
		}
        return false;
    }
}