Jump to content

_MinimizeToTray UDF


wraithdu
 Share

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))
_MinimizeToTray($gui)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUISetState()

While 1
    Sleep(1000)
WEnd

Func _Exit()
    If Not $bExit Then
        $bExit = True
        WinSetTitle($gui, "", "_MinimizeToTray Example w/ Tray Icon")
        _MinimizeToTray($gui, True)
        TraySetState(2)
    Else
        Exit
    EndIf
EndFunc

_MinimizeToTray.au3

Link to comment
Share on other sites

  • 2 months later...
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...