Jump to content
Sign in to follow this  

_MinimizeToTray UDF

Recommended Posts


Since I recently improved my toolbar button hiding function, I decided it would be nice to have as a UDF as well. With this UDF you can add minimize-to-tray functionality to your GUI very easily. There are a few caveats. For it to work as a UDF, these options must be set, and ARE set automatically -

Opt("GUIOnEventMode", 1); OnEvent mode
Opt("TrayOnEventMode", 1); ditto
Opt("TrayMenuMode", 1); no default tray menu (no pause or exit), user can still create custom menu
Opt("GUIEventOptions", 1); minimize, maximize, and restore only send notifications, we handle the actions

and these events registered -

; set min/max/restore events
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_OnEventMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_OnEventMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "_OnEventRestore")

Lastly, if you go with the option to show / hide the tray icon also, it looks better to set the #NoTrayIcon option initially in your script, unless your GUI is starting minimized, in which case you'll want to omit that option.

Example -

#include <_MinimizeToTray.au3>
#include <WindowsConstants.au3>

Global $bExit = False
Global $gui = GUICreate("_MinimizeToTray Example", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX))

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")


While 1

Func _Exit()
    If Not $bExit Then
        $bExit = True
        WinSetTitle($gui, "", "_MinimizeToTray Example w/ Tray Icon")
        _MinimizeToTray($gui, True)


Share this post

Link to post
Share on other sites

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this