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
Minimize/Restore All Windows
Return to DisplayFusion Scripted Functions (Macros)
Description
This script will minimize all open windows when run the first time, and will restore all open windows when run the second time.
Language
C#.net
Minimum Version
7.0.0+
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
Jan 6, 2015
Date Last Modified
Jan 6, 2015
Scripted Function (Macro) Code
Copy
Select All
using System; using System.Drawing; using System.Collections.Generic; using System.Text; // 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 { //an enum to set the script state private enum ScriptState { Normal = 0, Minimized = 1 } public static void Run(IntPtr windowHandle) { //constants to set and get the window state property const string windowStateProperty = "MinimizeAndRestoreWindows_WindowState"; //random values to use as property values const int normalState = 432985; const int maximizedState = 347561; //if the script is in it's minimized state, restore the saved window positions if(IsScriptInMinimizeState()) { //loop over every window foreach(IntPtr window in BFS.Window.GetAllWindowHandles()) { //check for a saved property IntPtr windowState = BFS.Window.GetWindowProperty(window, windowStateProperty); //if we couldnt find a property, continue to the next window if(windowState == IntPtr.Zero) continue; //if the window was in a normal state, restore it if(windowState.ToInt64() == normalState) BFS.Window.Restore(window); //if the window was in a maximized state, maximize it if(windowState.ToInt64() == maximizedState) BFS.Window.Maximize(window); //remove the property from the window BFS.Window.RemoveWindowProperty(window, windowStateProperty); } //reset the script state SetScriptState(ScriptState.Normal); //exit the script return; } //if we got to this point we should save all of the windows, then minimize them //loop through all of the visiable windows, save their state, then minimize then foreach(IntPtr window in BFS.Window.GetVisibleWindowHandles()) { if(BFS.Window.IsMaximized(window)) BFS.Window.SetWindowProperty(window, windowStateProperty, new IntPtr(maximizedState)); if(BFS.Window.IsRestored(window)) BFS.Window.SetWindowProperty(window, windowStateProperty, new IntPtr(normalState)); BFS.Window.Minimize(window); } //set the script state to minimized SetScriptState(ScriptState.Minimized); } //this function quickly checks to see whether we need to restore previously minimized windows private static bool IsScriptInMinimizeState() { //read the setting value string state = BFS.ScriptSettings.ReadValue("Minimize and Restore Windows State"); //return the saved state. if no state saved, return false return (state.Length != 0) && (state.Equals("minimized")); } //this function saves the script state private static void SetScriptState(ScriptState state) { //save the state BFS.ScriptSettings.WriteValue("Minimize and Restore Windows State", (state == ScriptState.Normal) ? "normal" : "minimized"); } }