WoodGrain Posted January 5, 2023 Share Posted January 5, 2023 I have the below code I've tried but the right-click menu items do nothing, I'm guessing it's on account of TrayGetMsg()? Any help would be much appreciated! expandcollapse popupOpt("TrayMenuMode", 3) TrayIcon() Func TrayIcon() Global $trayAbout = TrayCreateItem("About") TrayItemSetOnEvent(-1, "IconAbout") Global $traySettings = TrayCreateItem("Settings") TrayItemSetOnEvent(-1, "IconSettings") TraySetOnEvent(-13, "About"); $TRAY_EVENT_PRIMARYDOUBLE Global $trayExit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "IconExit") TraySetClick(8); $TRAY_CLICK_SECONDARYDOWN TraySetState(1); Show the icon EndFunc Func IconAbout() MsgBox(0, "About", "This is info about the app") EndFunc Func IconSettings() StartGui() EndFunc Func IconExit() Exit EndFunc ; Primary app loop to do stuff While 1 ;I've tried adding in the TrayGetMsg() here but doesn't work Switch TrayGetMsg() Case $trayAbout IconAbout() EndSwitch ; do the rest of my app stuff in a loop every 20 seconds, this loop interval is required Sleep(20000) WEnd Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 (edited) take ideas maybe help expandcollapse popup#include <StringConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode. Local $bPaused = False TraySetIcon(StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1) & "\Icons\MyAutoIt3_Blue.ico") #Region === Tray_Menu === Local $idPaused = TrayCreateItem("Pause", -1, -1, $TRAY_ITEM_RADIO) TrayItemSetState(-1, $TRAY_UNCHECKED) TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") #EndRegion === Tray_Menu === ToolTip(@ScriptName & @CRLF & " ", @DesktopWidth / 2, @DesktopHeight / 5, "Started", 1) Sleep(3000) ToolTip("") While 1 _GetTrayMsg() Sleep(50) WEnd Exit ;---------------------------------------------------------------------------------------- Func GoToExit() ; exit Exit EndFunc ;==>GoToExit ;---------------------------------------------------------------------------------------- Func _GetTrayMsg() While 1 Switch TrayGetMsg() Case $TRAY_EVENT_SECONDARYDOUBLE ; ConsoleWrite("$TRAY_EVENT_SECONDARYDOUBLE" & @CRLF) Case $TRAY_EVENT_PRIMARYDOUBLE ; Paused the loop. TogglePause() Case $idPaused ; Paused the loop. TogglePause() Case $idExit ; Exit the loop. GoToExit() EndSwitch If $bPaused = False Then ExitLoop WEnd EndFunc ;==>_GetTrayMsg ;---------------------------------------------------------------------------------------- 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 ;~ ConsoleWrite("$bPaused=" & $bPaused & @CRLF) EndFunc ;==>TogglePause ;---------------------------------------------------------------------------------------- Edited January 5, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 (edited) OnEvent mode also work! expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Example() Func Example() TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("test") TrayItemSetOnEvent(-1, "_test") TrayCreateItem("") ; Create a separator line. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button. TraySetOnEvent($TRAY_EVENT_SECONDARYDOUBLE, "_test") ; TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Sleep(100) ; An idle loop. WEnd EndFunc ;==>Example Func About() ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. EndFunc ;==>About Func ExitScript() Exit EndFunc ;==>ExitScript Func _test() ConsoleWrite("$TRAY_EVENT_SECONDARYDOUBLE" & @CRLF) EndFunc Edited January 5, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 37 minutes ago, WoodGrain said: but the right-click menu items do nothing no one works ? I know that I know nothing Link to comment Share on other sites More sharing options...
WoodGrain Posted January 5, 2023 Author Share Posted January 5, 2023 These look like they loop every 50 and 100 ms, I need my program loop to be several seconds, normally between 5 seconds and 60 seconds depending on conditions ; do the rest of my app stuff in a loop every 20 seconds, this loop interval is required Sleep(20000) Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 Then to prefer OnEvent mode. with the right click what happened? I know that I know nothing Link to comment Share on other sites More sharing options...
WoodGrain Posted January 5, 2023 Author Share Posted January 5, 2023 I see the 3 menu items, but clicking them does nothing. Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 (edited) 1 hour ago, ioa747 said: OnEvent mode also work! expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Example() Func Example() TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("test") TrayItemSetOnEvent(-1, "_test") TrayCreateItem("") ; Create a separator line. TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "About") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button. TraySetOnEvent($TRAY_EVENT_SECONDARYDOUBLE, "_test") ; TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Sleep(100) ; An idle loop. WEnd EndFunc ;==>Example Func About() ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. EndFunc ;==>About Func ExitScript() Exit EndFunc ;==>ExitScript Func _test() ConsoleWrite("$TRAY_EVENT_SECONDARYDOUBLE" & @CRLF) EndFunc double right click = ConsoleWrite("$TRAY_EVENT_SECONDARYDOUBLE" & @CRLF) double left click Msgbox About Edited January 5, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
WoodGrain Posted January 5, 2023 Author Share Posted January 5, 2023 Wait, I've re-read that help article and it looks like I'm missing this from my code: Opt("TrayOnEventMode", 1) Link to comment Share on other sites More sharing options...
WoodGrain Posted January 5, 2023 Author Share Posted January 5, 2023 5 minutes ago, WoodGrain said: Wait, I've re-read that help article and it looks like I'm missing this from my code: Opt("TrayOnEventMode", 1) Adding this line in got the menu working. Link to comment Share on other sites More sharing options...
ioa747 Posted January 5, 2023 Share Posted January 5, 2023 I know that I know nothing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now