Jump to content

Tray Example


ioa747
 Share

Recommended Posts

 

; https://www.autoitscript.com/forum/topic/209550-tray-example/

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7

#include <StringConstants.au3>
#include <TrayConstants.au3>

Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.

Local $bPaused = False
TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")

#Region === Tray_Menu ===
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TogglePause")

Local $idPaused = TrayCreateItem("Pause", -1, -1, $TRAY_ITEM_RADIO)
TrayItemSetOnEvent(-1, "TogglePause")
TrayItemSetState(-1, $TRAY_UNCHECKED)

TrayCreateItem("") ; Create a separator line.
Local $idExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "GoToExit")

#EndRegion === Tray_Menu ===

ToolTip(@ScriptName & @CRLF & " ", @DesktopWidth / 2, @DesktopHeight / 5, "Started", 1)
Sleep(3000)
ToolTip("")

While 1
    _GetTrayStatus()
    Sleep(10)
WEnd

GoToExit()
;----------------------------------------------------------------------------------------
Func GoToExit()    ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _GetTrayStatus()
    While 1
;~      ConsoleWrite("-loop" & @CRLF)
        If $bPaused = False Then
            ExitLoop
        Else  ; calm down and stay
            Sleep(500)
        EndIf
    WEnd
EndFunc   ;==>_GetTrayStatus
;----------------------------------------------------------------------------------------
Func TogglePause()

    If $bPaused = False Then
        $bPaused = True
        TrayItemSetState($idPaused, $TRAY_CHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Red.ico")
    Else
        $bPaused = False
        TrayItemSetState($idPaused, $TRAY_UNCHECKED)    ; $TRAY_UNCHECKED, $TRAY_CHECKED
        TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico")
    EndIf

EndFunc   ;==>TogglePause

;----------------------------------------------------------------------------------------

 

Edited by ioa747

I know that I know nothing

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

×
×
  • Create New...