Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
CloudShow Manager
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
TrayStatus
VoiceBot
WallpaperFusion
Display
Fusion
by Binary Fortress Software
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
Features
Free vs Pro
More
Screenshots
Scripted Functions (Macros)
Languages
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Purchase
Login / Register
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Focus Topmost Window on Specific Monitor
Return to DisplayFusion Scripted Functions (Macros)
Description
This script will focus the topmost window on the monitor specified on line 17.
Language
C#.net
Minimum Version
9.5+
Created By
Keith Lammers (BFS)
Contributors
Thomas Malloch (BFS)
Date Created
Jul 30, 2019
Date Last Modified
Jul 30, 2019
Scripted Function (Macro) Code
Copy
Select All
using System; using System.Collections.Generic; using System.Drawing; using System.Runtime.InteropServices; public static class DisplayFusionFunction { [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd); // Some constants const uint GW_HWNDNEXT = 2; public static void Run(IntPtr windowHandle) { // Set the monitor ID here uint monitorID = 401; // Find the topmost window on the next monitor IntPtr window = GetTopmostWindowOnMonitor(monitorID); // Focus the next window on the next monitor BFS.Window.Focus(window); } private static IntPtr GetTopmostWindowOnMonitor(uint id) { // Get the visible window handles for that monitor HashSet<IntPtr> visibleWindows = new HashSet<IntPtr>( BFS.Window.GetVisibleWindowHandlesByMonitor(id) ); // Enumerate through the monitors, starting with the focused window, and moving down // Only enumerate if we havn't found the windows yet for(IntPtr window = BFS.Window.GetFocusedWindow(); ; window = GetWindow(window, GW_HWNDNEXT)) { // Check to see if there are no windows left if(window == IntPtr.Zero) break; // Check to see if the window is visible. if it's not, ignore it if(!visibleWindows.Contains(window)) continue; // If it is a window we should ignore, ignore it if(IsDisplayFusionWindowOrHiddenExplorerWindow(window)) continue; // Get the monitor this window is in uint monitor = BFS.Monitor.GetMonitorIDByWindow(window); // If the monitor isn't in our collection, get the next window if(id != monitor) continue; return window; } // Return IntPtr.Zero if we didn't find anything return IntPtr.Zero; } 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; } }