Simple minimize windows to tray.

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
MiM
Posts: 61
Joined: 20 Apr 2021, 04:31

Simple minimize windows to tray.

08 Jul 2021, 00:01

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.
Last edited by MiM on 29 Jul 2021, 07:38, edited 4 times in total.
ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: Simple minimize windows to tray.

08 Jul 2021, 04:57

Like it. Thanks
MancioDellaVega
Posts: 83
Joined: 16 May 2020, 12:27
Location: Italy

Re: Simple minimize windows to tray.

10 Jul 2021, 15:34

Very nice... thanks...
Courses on AutoHotkey
User avatar
MiM
Posts: 61
Joined: 20 Apr 2021, 04:31

Re: Simple minimize windows to tray.

29 Jul 2021, 07:41

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)
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Simple minimize windows to tray.

30 Jan 2022, 10:39

One minor bug: try to hide some windows and then reload the script.
You can easily fix it with OnExit().
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Kein
Posts: 15
Joined: 07 Mar 2016, 15:19

Re: Simple minimize windows to tray.

21 May 2023, 01:54

Thanks, stealing this.
User avatar
V0RT3X
Posts: 233
Joined: 20 May 2023, 21:59
Contact:

Re: Simple minimize windows to tray.

21 May 2023, 07:28

Does this work similar to how Windows built in Task View button does? As in does it also maximize?
unnamed9710
Posts: 6
Joined: 02 Jun 2023, 08:55

Re: Simple minimize windows to tray.

26 Aug 2023, 21:34

Thank you for the amazing script. But it doesn't work with Windows Security settings window? I encounter Error: Cant toad icon.
Image
Image

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 239 guests