Jump to content

Minimize to System Tray


Recommended Posts

I am curious if this is possible. I would like the Gui that I have to minimize to the System tray icon that is set. Currently the Window minimizes and is available to restore in an option above the Start Menu. i just want the GUI to go straight down to the System Tray. Can somebody assist me what I am doing wrong here please?

Here is what I am seeing when I click on the minimize option.

image.png.1528db118a4fc352ba1acffc62bcaf1b.png

 

Here is the code that I have.

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <Constants.au3>
#include <TabConstants.au3>
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 9)
Local $formMain
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_RestoreTray")
$trayGUI = TrayCreateItem("GUI", -1, -1, $TRAY_ITEM_RADIO)
$trayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
_GUI()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg = $GUI_EVENT_MINIMIZE
            GUIDelete($formMain)
            ;GUISetState(@SW_MINIMIZE, $formMain)
            ;GUISetState(@SW_HIDE, $formMain)
            TraySetState(1) ; show
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Func _GUI()
#Region ### START Koda GUI section ### Form=
$formMain = GUICreate("GUI", 277, 573, @DesktopWidth - 292, @DesktopHeight - 650, BitOR($GUI_SS_DEFAULT_GUI,$WS_MINIMIZE,$WS_TABSTOP,$WS_OVERLAPPEDWINDOW), "", WinGetHandle(AutoItWinGetTitle()))
$tabNetwork = GUICtrlCreateTab(10, 10, 259, 553)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")
GUICtrlSetState(-1,$GUI_SHOW)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

EndFunc   ;==>_GUI
Func _Exit()
    Exit
EndFunc   ;==>_Exit
Func _RestoreTray()
    ;_GUI()
    GUISetState(@SW_RESTORE, $formMain)
    GUISetState(@SW_SHOW, $formMain)
    ;TraySetState(2) ; hide
EndFunc   ;==>_RestoreTray

 

Link to comment
Share on other sites

  • Developers

Something to have a look at:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <Constants.au3>
#include <TabConstants.au3>
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 9)

$trayGUI = TrayCreateItem("GUI", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetOnEvent(-1, "_ToggleTray")
$trayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")

$formMain = GUICreate("GUI", 277, 573, @DesktopWidth - 292, @DesktopHeight - 650)
$tabNetwork = GUICtrlCreateTab(10, 10, 259, 553)
$TabSheet1 = GUICtrlCreateTabItem("Tab1")
GUICtrlSetState(-1, $GUI_SHOW)
$TabSheet2 = GUICtrlCreateTabItem("Tab2")
GUICtrlCreateTabItem("")
GUISwitch($formMain)
;~ GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_MINIMIZE
            GUISetState(@SW_HIDE)
            TrayItemSetState($trayGUI, $TRAY_UNCHECKED)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _ToggleTray()
    If BitAND(TrayItemGetState($trayGUI), $TRAY_CHECKED) Then
        GUISetState(@SW_SHOW)
    Else
        GUISetState(@SW_HIDE)
    EndIf
EndFunc   ;==>_ToggleTray

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...