Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
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
VoiceBot
WallpaperFusion
Home
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
Incredible Desktop Wallpaper
Monitor Configuration
Monitor Splitting
Powerful Functions
Triggers
Multi-Monitor Taskbars
Useful Windows 10 Tweaks
Useful Windows 8 Tweaks
Windows Lock Screen
Multi-Monitor Screen Savers
Monitor Fading
Window Snapping
Window Management
Mouse Management
Alt+Tab Handler
Window Position Profiles
Desktop Icon Profiles
Remote Control
Available in dozens of Languages
Easy Administration
Free vs Pro
Purchase
Screenshots
Languages
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Scripted Functions (Macros)
Display
Fusion
by Binary Fortress Software
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Span Custom Set of Monitors (Horizontal Only)
Return to DisplayFusion Scripted Functions (Macros)
Description
This script will toggle spanning a custom group of horizontally arranged monitors. Make sure to specify the monitor IDs from left-to-right in the monitorsToSpan array on line 16.
Language
C# (.Net)
Minimum Version
9.4.3+
Created By
Keith Lammers (BFS)
Contributors
-
Date Created
Feb 26, 2019
Date Last Modified
Jul 8, 2019
Scripted Function (Macro) Code
Copy
Select All
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) { // Specify the monitors you want to span here // Enter them in order from left to right (check the Monitor Configuration window) uint[] monitorsToSpan = { 2, 1 }; // Calculate the window size Rectangle leftMonitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorsToSpan[0]); int windowWidth = 0; int windowHeight = leftMonitorWorkArea.Height; // Loop through the monitors to add the widths together, and set the lowest common height foreach (uint monitorID in monitorsToSpan) { Rectangle monitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorID); windowWidth += monitorWorkArea.Width; if (monitorWorkArea.Height < windowHeight) { windowHeight = monitorWorkArea.Height; } } // Set the target location and size for the spanned window int windowLocationX = leftMonitorWorkArea.X; int windowLocationY = leftMonitorWorkArea.Y; Rectangle calculatedSize = new Rectangle(windowLocationX, windowLocationY, windowWidth, windowHeight); // If the window is already spanned (X is ignored because it can vary slightly), restore its previous size // Otherwise, save its size and span it Rectangle currentWindowBounds = BFS.Window.GetBounds(windowHandle); if (currentWindowBounds.Y == calculatedSize.Y && currentWindowBounds.Width == calculatedSize.Width && currentWindowBounds.Height == calculatedSize.Height) { LoadWindowPosition(windowHandle); } else { SaveWindowPosition(windowHandle); BFS.Window.SetSizeAndLocation(windowHandle, calculatedSize.X, calculatedSize.Y, calculatedSize.Width, calculatedSize.Height); } } private static void SaveWindowPosition(IntPtr window) { // Build the settings string with the window values Rectangle bounds = BFS.Window.GetBounds(window); string settings = string.Format("{0}|{1}|{2}|{3}|{4}", window.ToInt64(), bounds.X, bounds.Y, bounds.Width, bounds.Height); // Write the setting to the registry BFS.ScriptSettings.WriteValue(BFS.Application.GetMainFileByWindow(window), settings); } private static void LoadWindowPosition(IntPtr window) { // Split up the settings string into its seperate values string[] settings = BFS.ScriptSettings.ReadValue(BFS.Application.GetMainFileByWindow(window)).Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries); // Check to see if we have enough parameters saved to the setting if(settings.Length != 5) throw new Exception("Incorrect settings format"); // Set the values Rectangle savedWindowPosition = new Rectangle( Convert.ToInt32(settings[1]), Convert.ToInt32(settings[2]), Convert.ToInt32(settings[3]), Convert.ToInt32(settings[4])); // Move the window BFS.Window.SetSizeAndLocation(window, savedWindowPosition.X, savedWindowPosition.Y, savedWindowPosition.Width, savedWindowPosition.Height); } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get DisplayFusion Merch