Page 1 of 1

Simple minimize windows to tray.

Posted: 08 Jul 2021, 00:01
by MiM
Tried making the most basic "minimize windows to tray" script.

Here it is:

Code: Select all

#NoEnv
#Persistent
#SingleInstance, Force
SetFormat, IntegerFast, Hex
SetBatchLines, -1
SetWinDelay, -1

Global Cached_Windows := {}

Menu, Tray, NoStandard
Menu, Tray, Icon, C:\Windows\system32\shell32.dll, 3
Menu, Tray, Add, Exit, Exit
Menu, Tray, Icon, Exit, C:\Windows\system32\shell32.dll, 113

;---------------------- Functions ----------------------
MenuItemClick(WinID, WinTitle, ItemName, ItemPosition) {
  WinShow, ahk_id %WinID%
  Cached_Windows.Delete(WinID)
  Menu, Tray, Delete, %ItemPosition%&
}
;-------------------------------------------------------
Return


!F1::
WinGet, WinID, ID, A
WinGet, WinIcon, ProcessPath, ahk_id %WinID%
WinGetTitle, WinTitle, ahk_id %WinID%
WinGet, Style, Style, ahk_id %WinID%
if (Style & 0xC00000) { ; If active window has titlebar
  ObjRawSet(Cached_Windows, WinID, WinID)
  BoundGivePar := Func("MenuItemClick").Bind(WinID, WinTitle)
  if (StrLen(WinTitle) > 50) {
    WinTitle := SubStr(WinTitle, 1, 50) "..."
  }
  Menu, Tray, Insert, 1&, %WinTitle%, %BoundGivePar%
  Menu, Tray, Icon, %WinTitle%, %WinIcon%
  WinHide, ahk_id %WinID%
}
Return


Exit:
For index, WinID in Cached_Windows {
  WinShow, ahk_id %WinID%
}
ExitApp
Return
• Alt+F1 to minimize any window to the script's tray icon.
• Right-click on the script's tray icon to view all minimized windows.

Maybe someone will find this useful (:

EDIT: Fixed up the code.

Re: Simple minimize windows to tray.

Posted: 08 Jul 2021, 04:57
by ozzii
Like it. Thanks

Re: Simple minimize windows to tray.

Posted: 10 Jul 2021, 15:34
by MancioDellaVega
Very nice... thanks...

Re: Simple minimize windows to tray.

Posted: 29 Jul 2021, 07:41
by MiM
Bumping this because i've fixed up the code and everything is working as it should now.
(except some windows don't have a titlebar but i don't know any other way to tell apart a proper window vs Progman and stuff like that)

Re: Simple minimize windows to tray.

Posted: 30 Jan 2022, 10:39
by amateur+
One minor bug: try to hide some windows and then reload the script.
You can easily fix it with OnExit().

Re: Simple minimize windows to tray.

Posted: 21 May 2023, 01:54
by Kein
Thanks, stealing this.

Re: Simple minimize windows to tray.

Posted: 21 May 2023, 07:28
by V0RT3X
Does this work similar to how Windows built in Task View button does? As in does it also maximize?

Re: Simple minimize windows to tray.

Posted: 26 Aug 2023, 21:34
by unnamed9710
Thank you for the amazing script. But it doesn't work with Windows Security settings window? I encounter Error: Cant toad icon.
Image
Image