Jump to content

Minimize GUI to tray


James
 Share

Recommended Posts

Hey,

If anyone ever needs this then here you go.

#include <Constants.au3>
#include <GUIConstants.au3>
#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Minimize")

$GUI = GUICreate("Minimize me", 460, 400)
GUICtrlCreateLabel("Press the minimize button to hide the window.", 125, 175)

GUISetState(@SW_SHOW)

While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            Exit
        Case $iMsg = $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
                        TraySetState(1)
    EndSelect
WEnd

Func Minimize()
    TraySetState(2)
    GuiSetState(@SW_SHOW)
EndFunc

-James

Link to comment
Share on other sites

i've change it just a bit for what i needed. thanks

; toggle show/hide by clicking tray icon
#include <Constants.au3>
#include <GUIConstants.au3>

Global $is_minimized = 0

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Toggle")

$GUI = GUICreate("Minimize me", 460, 400)
GUICtrlCreateLabel("Toggle show/hide by clicking tray icon", 125, 175)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            $is_minimized = 1
            debug("$is_minimized: " & $is_minimized)
    EndSwitch
WEnd

Func Toggle()
    If $is_minimized = 1 Then
        GuiSetState(@SW_SHOW)
        $is_minimized = 0
    Else
        GuiSetState(@SW_HIDE)
        $is_minimized = 1
    EndIf
    debug("$is_minimized: " & $is_minimized)
EndFunc

Func debug($a)
    ConsoleWrite(@SEC & " " & $a & @CRLF)
EndFunc
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...