Script to Minimize Maximise All Open Dialog Windows

Script to Minimize Maximise All Open Dialog Windows

Anonymous
Not applicable
2,493 Views
15 Replies
Message 1 of 16

Script to Minimize Maximise All Open Dialog Windows

Anonymous
Not applicable

Hi there,

I am needing a script to toggle minimise and maximise the existing open windows.

Anybody can help me?

0 Likes
Accepted solutions (3)
2,494 Views
15 Replies
Replies (15)
Message 2 of 16

miauuuu
Collaborator
Collaborator

3ds Max will be also an open window at the time of execution of the script. Do you want to minize it as well?

 

Be carefull:

 

(
local WM_SYSCOMMAND = 0x112
local SC_MINIMIZE = 0xf020
local SC_MAXIMIZE = 0xf030
local SC_RESTORE = 0xf120

for child in (windows.getChildrenHWND 0) do
(
windows.sendMessage child[1] WM_SYSCOMMAND SC_MINIMIZE 0
)
)

 

https://miauu-maxscript.com/
Message 3 of 16

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@miauuuu wrote:

3ds Max will be also an open window at the time of execution of the script. Do you want to minize it as well?

 

Be carefull:


The idea is correct, but perhaps too aggressive ... since this is not only about dialogues. Maybe this it will be better:

 

 

 

(
	WM_SYSCOMMAND 	= 0x0112
	SC_MINIMIZE 	= 0xF020
	SC_MAXIMIZE 	= 0xF030
	SC_RESTORE 		= 0xF120

	for hwnd in UIAccessor.GetPopupDialogs() do 
        UIAccessor.SendMessage hwnd WM_SYSCOMMAND SC_MINIMIZE 0
)

 

 

 

Message 4 of 16

Anonymous
Not applicable

Thank you very much. I don’t want 3ds max screen to be minimised. Only the dialog windows?

can it be like that?

can it work like a toggle to minimise and maximize?

0 Likes
Message 5 of 16

Anonymous
Not applicable

Thank you very much. Today away from my pc but  Will check this tomorrow and will let you know about results. Is this like a toggle?

0 Likes
Message 6 of 16

Anonymous
Not applicable

This works great!

 

Would you please help me in 2 more things :

1. Can it be possible to make it work like toggle ? to minimize all open and to maximize all minimised?

2. SME is disregarded when minimising. Is it possible to include that as well?

 

Thanks in advance.

 

0 Likes
Message 7 of 16

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

This works great!

 

Would you please help me in 2 more things :

1. Can it be possible to make it work like toggle ? to minimize all open and to maximize all minimised?

2. SME is disregarded when minimising. Is it possible to include that as well?

 

Thanks in advance.

 


SOLVED tag had to go to miauuuu. His answer is more correct than mine. When we want to MINIMIZE or MAXIMIZE a window, we expect a window with WS_MINIMIZEBOX or/and WS_MAXIMIZEBOX styles. In my case, I am giving a POPUP style window list. These windows could be designed for NORMAL placement and they should not be minimized or maximized. So, technically, I was wrong. 

We need to modify miauuuu's code and add a check that window has WS_MINIMIZEBOX or/and WS_MAXIMIZEBOX style. 

Message 8 of 16

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

2. SME is disregarded when minimising. Is it possible to include that as well?

SME is a WS_OVERLAPPED window, this is why it doesn't go in Popup Dialogs list

Message 9 of 16

Anonymous
Not applicable

Thanks for the detailed answer. 

Unfortunately I am dumb at scripting so I can't say I understood.

 

Can you please show me how to modify miauu's script?

 

Thanks for the greatest help!

0 Likes
Message 10 of 16

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
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.

  

Message 11 of 16

Anonymous
Not applicable

Thank you very much.😘😍

This is exactly what I wanted.

 

It minimizes the windows but I does not restore back with shift click.

I made a toolbar button and that is fine. It restores back with shift-click.

I am using 3ds max 2020.

 

FYI the open dialogs were sme and transform dialog and vfb.
Is it possible to fix?

 

0 Likes
Message 12 of 16

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

Thank you very much.😘😍

This is exactly what I wanted.

 

It minimizes the windows but I does not restore back with shift click.

I made a toolbar button and that is fine. It restores back with shift-click.

I am using 3ds max 2020.

 

FYI the open dialogs were sme and transform dialog and vfb.
Is it possible to fix?

 


what can be fixed? I do not understand what the problem is

 

Message 13 of 16

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

Ah... I guess. MAX ignores case for hotkeys.

I changed the code to use SHIFT+ or ALT+ for RESTORE

In case of using a hotkey you have to assign two hokeys to the macro (with and without ALT). For example, CTRL+M and ALT+M (or CTRL+ALT+M).. or any other key but with ALT

 

 

 

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 
	(
		alt = keyboard.shiftpressed or keyboard.altpressed
		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 alt then restoreWindow else minimizeWindow) hwnds
		
		--updateToolbarButtons()
	)
)			

 

 

 

ALT+ doesn't work for macrobuttons, SHIFT+ doesn't work for hotkeys. This is a built-in limitation

Message 14 of 16

Anonymous
Not applicable

Thank you very much. It is working now.

However working with the right ALT key. (which is better for me as I am left handed and holding the stylus on my left and my right hand is free to type)

 

And thank you for this info about the shift and the alt key for macros.

 

I want to get into maxscript.
Do you have any recommendation to start from?

 

0 Likes
Message 15 of 16

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

I want to get into maxscript.
Do you have any recommendation to start from?

 


You have to find and run a real project, put the MAXScript help as a Bible on your desktop and nightstand, and make friends on one of the popular 3DS MAX forums (AREA, CGTalk, etc.). This is how it works.

 🙂

Message 16 of 16

Anonymous
Not applicable

Thanks a lot. I will keep your advice.

0 Likes