TrayIt! can minimize apps to system tray (notification area), but it can't do the same when with the close button. Is there a tool that makes the act of closing an app become minimizing it to the notification area?

1 Answer 1


This AutoHotKey script makes the act of clicking the close button becomes minimizing the window to the taskbar. Together with TrayIt!, the whole process will minimizing it to the notification area.

#SingleInstance Force

; Add the ahk_class of the windows you want  minimize by clicking on the close button in this array:
Classes := "Notepad,CabinetWClass,IEFrame" ; ...
Loop, parse, Classes, `,
    GroupAdd, GroupName, ahk_class %A_LoopField%

SetTimer CheckMouse, -300

    CoordMode, Mouse, Screen
    MouseGetPos, mX, mY, WindowUnderMouse
    WinGetPos, wX, wY, wW, wH, ahk_id %WindowUnderMouse%
        CloseButton := (mY > wY and mY < wY+50 and (mX > wX + (wW-50) and mX < wX+wW))
    SetTimer CheckMouse, -300

#If (CloseButton)

        MouseGetPos,,, WindowUnderMouse
        WinGetClass, Class, ahk_id %WindowUnderMouse%
        If Class in %Classes%
            WinGet, id, ID, ahk_id %WindowUnderMouse%
            WinMinimize, ahk_id %WindowUnderMouse%

#If WinActive("ahk_group GroupName")

    !F4:: WinMinimize, A

#If ; turn off context sensitivity

DISABLE_CloseButton(id){ ;By RealityRipple at http://www.xtremevbtalk.com/archive/index.php/t-258725.html   
  WinGetPos,x,y,w,h,ahk_id %id%
  WinMove,ahk_id %id%,,%x%,%y%,%w%,% h-1
  WinMove,ahk_id %id%,,%x%,%y%,%w%,% h+1

ENABLE_CloseButton(id){ ;By Mosaic1 at http://www.xtremevbtalk.com/archive/index.php/t-258725.html  

Original post and the explanation for how the script works is from this Stack Overflow post: How to minimize a window by closing it?

  • unfortunately, this does not work with ManicTime
    – Ooker
    Commented May 2, 2019 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.