macroScript MinMaxDialogs
category: "DTS"
buttonText:"MINMAX"
toolTip:"Minimize/Restore(SHIFT) Dialogs"
autoUndoEnabled:off
silentErrors:off
(
local
GWL_STYLE = -16,
WS_MINIMIZEBOX = 0x00020000L,
WS_MAXIMIZEBOX = 0x00010000L,
WS_MINIMIZE = 0x20000000L,
WS_MAXIMIZE = 0x01000000L,
WS_VISIBLE = 0x10000000L,
WS_DISABLED = 0x08000000L,
WS_OVERLAPPEDWINDOW = 0x00CF0000L
local
GWL_EXSTYLE = -20,
WS_EX_TOOLWINDOW = 0x00000080L
local
WM_SYSCOMMAND = 0x112,
SC_MINIMIZE = 0xF020,
SC_MAXIMIZE = 0xF030,
SC_RESTORE = 0xF120
local MAXHWND = windows.getMAXHWND()
local _USER32 =
(
src="using System;"
src += "using System.Runtime.InteropServices;"
src += "class _user32"
src += "{"
src += " [DllImport(\"User32.DLL\", EntryPoint=\"GetWindowLong\")]"
src += " public static extern Int32 GetWindowLong(Int32 hWnd, Int32 index);"
src += "}"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(src)
_user32Assembly = compilerResults.CompiledAssembly
_user32Assembly.CreateInstance "_user32"
)
fn getStyle hwnd = (_USER32.GetWindowLong hwnd GWL_STYLE)
fn getExStyle hwnd = (_USER32.GetWindowLong hwnd GWL_EXSTYLE)
fn isVisible hwnd = (bit.and (getstyle hwnd) WS_VISIBLE) != 0
fn isDialog hwnd = (bit.and (getstyle hwnd) WS_OVERLAPPEDWINDOW) != 0 and (bit.and (getexstyle hwnd) WS_EX_TOOLWINDOW) == 0
fn isMinimizable hwnd = (bit.and (getstyle hwnd) WS_MINIMIZEBOX) != 0
fn isMaximizable hwnd = (bit.and (getstyle hwnd) WS_MAXIMIZEBOX) != 0
fn isMinimized hwnd = (bit.and (getstyle hwnd) WS_MINIMIZE) != 0
fn isMaximized hwnd = (bit.and (getstyle hwnd) WS_MAXIMIZE) != 0
fn isNormal hwnd = (bit.and (getstyle hwnd) (WS_MINIMIZE + WS_MAXIMIZE)) == 0
mapped fn minimizeWindow hwnd = if not isMinimized hwnd do windows.sendmessage hwnd WM_SYSCOMMAND SC_MINIMIZE 0
mapped fn maximizeWindow hwnd = if not isMaximized hwnd do windows.sendmessage hwnd WM_SYSCOMMAND SC_MAXIMIZE 0
mapped fn restoreWindow hwnd = if not isNormal hwnd do windows.sendmessage hwnd WM_SYSCOMMAND SC_RESTORE 0
on execute do
(
shift = keyboard.shiftpressed
hwnds = for w in (windows.getchildrenhwnd 0) where (w[2] == MAXHWND or w[6] == MAXHWND) and isDialog w[1] and isVisible w[1] collect w[1]
(if shift then restoreWindow else minimizeWindow) hwnds
--updateToolbarButtons()
)
)
this macroscript minimizes and restores MAX dialogs.
with a simple click (or hotkey) it minimizes all visible dialogs, with SHIFT + click (or SHIFT + hotkey) restores the dialogs.
maximizing doesn't make sense for multiple dialogs, so I don't do it for all, but if some dialog has been maximized before, it will be restored to its previuos state.
the script must be saved as an MCR file and placed in one of the MAX macroscripts directories.