Minimize all windows and maximize again Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
_Rapid_
Posts: 20
Joined: 19 Apr 2020, 10:40

Minimize all windows and maximize again

Post by _Rapid_ » 24 Apr 2020, 05:57

Hi,
i have some code to minimize all windows on my desktop I am also able to maximize the previously minimized windows again. But here something happens which is not intended. With multiple monitors this leads to my taskbar now extending over the whole screen... Is there a remedy for this?

Code: Select all

; Minimize All Windows
#a:: 
	WinGet, WindowList, List,,, Program Manager
	Loop, %WindowList%
	{
		WinMinimize, % "ahk_id " . WindowList%A_Index%
	}
return

; Maximize All Windows
#b:: 
	WinGet, WindowList, List,,, Program Manager
	Loop, %WindowList%
	{
		WinMaximize, % "ahk_id " . WindowList%A_Index%
	}
return
I can solve this issue if i restart the explorer.exe, but that does not realy feel like a solution...

Rohwedder
Posts: 7555
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Minimize all windows and maximize again  Topic is solved

Post by Rohwedder » 24 Apr 2020, 07:59

Hallo,
try:

Code: Select all

; Minimize All Windows
#a:: 
	WinGet, WindowList, List,,, Program Manager
	Loop, %WindowList%
	{
		WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
		IF (Class <> "Shell_SecondaryTrayWnd" And Class <> "Shell_TrayWnd")
			WinMinimize, % "ahk_id " . WindowList%A_Index%
	}
return

; Maximize All Windows
#b:: 
	WinGet, WindowList, List,,, Program Manager
	Loop, %WindowList%
	{
		WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
		IF (Class <> "Shell_SecondaryTrayWnd" And Class <> "Shell_TrayWnd")
			WinMaximize, % "ahk_id " . WindowList%A_Index%
	}
return

_Rapid_
Posts: 20
Joined: 19 Apr 2020, 10:40

Re: Minimize all windows and maximize again

Post by _Rapid_ » 24 Apr 2020, 09:10

Thanks (Danke sehr) this works well! I also edited it with WinRestore :)

_Rapid_
Posts: 20
Joined: 19 Apr 2020, 10:40

Re: Minimize all windows and maximize again

Post by _Rapid_ » 29 Apr 2020, 07:48

Lets say I want to restore my old windows but keep the last activated window in the foreground, I tried it with this here, but it seems not to work propper, since it does not bring the last active window back in the focus. Has anyone an idea?

Code: Select all

; Restore All Windows
#c:: 
	WinGet, WindowList, List,,, Program Manager
	WinGetTitle, active_title, A
	Loop, %WindowList%
	{
		WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
		IF (Class <> "Shell_SecondaryTrayWnd" And Class <> "Shell_TrayWnd")
			WinRestore, % "ahk_id " . WindowList%A_Index%
	}
	WinActivate, %active_title%
    WinWaitActive, %active_title%, , 3
return

Rohwedder
Posts: 7555
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Minimize all windows and maximize again

Post by Rohwedder » 29 Apr 2020, 09:24

Here your script works!

Just for fun I have changed a few things, but it stays the same! Here it works!

Code: Select all

; Restore All Windows
#c Up::
active_ID := WinActive("A")
WinGet, WindowList, List,,, Program Manager
Loop, %WindowList%
{
	WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
	IF Class not contains Shell_TrayWnd,Shell_SecondaryTrayWnd
		WinRestore, % "ahk_id " . WindowList%A_Index%
}
WinActivate,% "ahk_id " active_ID
return

_Rapid_
Posts: 20
Joined: 19 Apr 2020, 10:40

Re: Minimize all windows and maximize again

Post by _Rapid_ » 30 Apr 2020, 09:26

OK, thanks for confirming that the script of mine works. That's good!

You can already see from line "WinWaitActive, %active_title%, , 3" that I was a bit "desperate" why the script didn't work, so I added this line as a brute force method :D

But a little question: Why did the same script only work for me after I did a reboot? Short info, I use Notepad++ to program the AHK scripts and then start them via double click and if necessary I overwrite the old instance with the new one...

Another question: What especially makes your last skript better than my, just for research interest :)

And thanks again for your answer!!!

Rohwedder
Posts: 7555
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Minimize all windows and maximize again

Post by Rohwedder » 30 Apr 2020, 10:31

I did not say that my last script was better!
The only thing: Two windows can have the same title but never the same ID.

nelvin08
Posts: 97
Joined: 27 Mar 2022, 23:13

Re: Minimize all windows and maximize again

Post by nelvin08 » 07 Feb 2023, 10:22

Hey Guys,

First, thank you for this. I tried and it worked but there are issues.

For some reason, it doesn't let the last active app to be the foreground after restoring. Also, after restoring, all the apps on my desktop (3 monitors) all completely disappear and I can't even right click on the desktop.

Below is my code where I decided to use #D as the same hotkey for both minimizing and maximizing. Thank you

Also, if I will be taking it another step further, is there a way to just show desktop rather than minimizing all the apps one by one? Is there any caveat to doing that? And then on the second press, it should restore all.

Code: Select all

#MaxThreadsperHotkey 2
#D::

Previouskey:= !PreviousKey

if PreviousKey
{
WinGet, WindowList, List,,, Program Manager
Loop, %WindowList%
{
	WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
	IF (Class <> "Shell_SecondaryTrayWnd" And Class <> "Shell_TrayWnd")
	WinMinimize, % "ahk_id " . WindowList%A_Index%
}
return
}
else
{
active_ID := WinActive("A")
WinGet, WindowList, List,,, Program Manager
Loop, %WindowList%
{
	WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
	IF Class not contains Shell_TrayWnd,Shell_SecondaryTrayWnd
	WinRestore, % "ahk_id " . WindowList%A_Index%
}
WinActivate, % "ahk_id " active_ID
return
}
return

nelvin08
Posts: 97
Joined: 27 Mar 2022, 23:13

Re: Minimize all windows and maximize again

Post by nelvin08 » 08 Feb 2023, 05:58

I decided to use the native windows functionality #d to show desktop and just use #f for the hotkey.

Below is my code but for some reason, it restores my microsoft teams as well even though it is already in the system panel (I already closed not but didn't force close / quit)

@_Rapid_
@Rohwedder

Also, is there an issue with using #d with this code since it's technically just showing desktop and not minimizing the apps.

Code: Select all

#F::
active_ID := WinActive("A")
WinGet, WindowList, List,,, Program Manager
Loop, %WindowList%
{
	WinGetClass, Class, % "ahk_id " . WindowList%A_Index%
	IF Class not contains Shell_TrayWnd,Shell_SecondaryTrayWnd
	WinRestore, % "ahk_id " . WindowList%A_Index%
}
WinActivate, % "ahk_id " active_ID
return

Post Reply

Return to “Ask for Help (v1)”