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?

Close All Visible Windows

Description
This function closes all visible windows.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Oct 6, 2014
Date Last Modified
Jan 2, 2024

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
//   - Window Location target when run by a Window Location 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)
	{
		//check if the user actually wants to run this function
		if (!BFS.Dialog.GetUserConfirm("Are you sure you want to close every open application?"))
			return;
		
		//loop though all of the open application by their ID and close them
		foreach (IntPtr window in BFS.Window.GetVisibleWindowHandles())
		{
			if (!IsDisplayFusionWindowOrHiddenExplorerWindow(window))
			{
				BFS.Window.Close(window);
			}
		}
	}
	
	private static bool IsDisplayFusionWindowOrHiddenExplorerWindow(IntPtr window)
    {
        //ignore any DisplayFusion windows (title bar buttons, etc.)
        //ignore pesky hidden explorer.exe windows
        string windowClass = BFS.Window.GetClass(window);
        if ((windowClass.StartsWith("DF", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("EdgeUiInputTopWndClass", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("EdgeUiInputWndClass", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("NativeHWNDHost", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("ModeInputWnd", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("MetroGhostWindow", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("ImmersiveLauncher", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("ApplicationManager_ImmersiveShellWindow", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("Shell_TrayWnd", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("WorkerW", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("Progman", StringComparison.OrdinalIgnoreCase)) ||
            (windowClass.Equals("SearchPane", StringComparison.OrdinalIgnoreCase)))
		{
            return true;
        }
		else
		{
			return false;	
		}
	}
}