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 { const string X = "ToggleWindowSpanTwoMonitors_X"; const string Y = "ToggleWindowSpanTwoMonitors_Y"; const string Width = "ToggleWindowSpanTwoMonitors_Width"; const string Height = "ToggleWindowSpanTwoMonitors_Height"; public static void Run(IntPtr windowHandle) { //adjust this variable to where you want the window to span Rectangle targetSpanBounds = new Rectangle(0, 0, 3840, 1080); //get the properties of the window IntPtr x = BFS.Window.GetWindowProperty(windowHandle, X); IntPtr y = BFS.Window.GetWindowProperty(windowHandle, Y); IntPtr width = BFS.Window.GetWindowProperty(windowHandle, Width); IntPtr height = BFS.Window.GetWindowProperty(windowHandle, Height); //restore the window if we need to if(!BFS.Window.IsRestored(windowHandle)) BFS.Window.Restore(windowHandle); //make a rectangle out of the properties Rectangle originalBounds = new Rectangle((int)x.ToInt64(), (int)y.ToInt64(), (int)width.ToInt64(), (int)height.ToInt64()); //if the rectangle is empty, the original bounds properties didn't exist. //span the window and set the original bounds if(originalBounds.Equals(Rectangle.Empty)) { //get the window bounds originalBounds = BFS.Window.GetBounds(windowHandle); //set the original window bound properties BFS.Window.SetWindowProperty(windowHandle, X, new IntPtr(originalBounds.X)); BFS.Window.SetWindowProperty(windowHandle, Y, new IntPtr(originalBounds.Y)); BFS.Window.SetWindowProperty(windowHandle, Width, new IntPtr(originalBounds.Width)); BFS.Window.SetWindowProperty(windowHandle, Height, new IntPtr(originalBounds.Height)); //span the window BFS.Window.SetSizeAndLocation(windowHandle, targetSpanBounds.X, targetSpanBounds.Y, targetSpanBounds.Width, targetSpanBounds.Height); //exit the script return; } //if we got this far, that means that the window is spanned. reset the window size BFS.Window.SetSizeAndLocation(windowHandle, originalBounds.X, originalBounds.Y, originalBounds.Width, originalBounds.Height); //remove the window properties BFS.Window.RemoveWindowProperty(windowHandle, X); BFS.Window.RemoveWindowProperty(windowHandle, Y); BFS.Window.RemoveWindowProperty(windowHandle, Width); BFS.Window.RemoveWindowProperty(windowHandle, Height); } }