Processing Ajax...
Save 25% on our desktop apps during our Black Friday/Cyber Monday sale!Save 25% on our desktop apps during our Black Friday/Cyber Monday sale, including DisplayFusion, ClipboardFusion, FileSeek, LogFusion, TrayStatus, and VoiceBot!Save 25% on our desktop apps during our Black Friday/Cyber Monday sale!

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Select Window and Move to Selected Monitor

Description
This script will show a list of open windows. When you select one, it will show the monitor selector, allowing you to choose which monitor it should be moved to.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Jul 27, 2018
Date Last Modified
Jul 27, 2018

Scripted Function (Macro) Code

using System;
using System.Drawing;
using System.Collections.Generic;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        Dictionary<string, IntPtr> windows = new Dictionary<string, IntPtr>();
        foreach (IntPtr window in BFS.Window.GetVisibleAndMinimizedWindowHandles())
        {
            if (IsDisplayFusionWindowOrHiddenExplorerWindow(window))
                continue;
        
            string title = BFS.Window.GetText(window);
            if(string.IsNullOrEmpty(title))
                continue;
                
            if(windows.ContainsKey(title))
            {
                int i;
                for(i = 1; windows.ContainsKey(title + "(" + i + ")") ; i++)
                {
                }
                
                windows.Add(title + "(" + i + ")", window);
            }
            else
            {
                windows.Add(title, window);
            }
        }
        
        string selectedWindow = BFS.Dialog.GetUserInputList("Select the window to move...", new List<string>(windows.Keys).ToArray());
        BFS.Window.MoveToMonitor(BFS.Monitor.ShowMonitorSelector(), windows[selectedWindow]);
    }
    
    private static bool IsDisplayFusionWindowOrHiddenExplorerWindow(IntPtr window)
	{
        //ignore any DisplayFusion windows (title bar buttons, etc.)
        //ignore pesky hidden explorer.exe windows
        if((BFS.Window.GetClass(window).StartsWith("DF", 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;
	}
}