jacky998877 Posted December 11, 2022 Share Posted December 11, 2022 (edited) after i clicked on the tray menu item "pause" and then if i want to click "exit the program" , it doesnt exit #include <AutoItConstants.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. TrayCreateItem("exit_the_program--") TrayItemSetOnEvent(-1, "Exit_the_program") TrayCreateItem("pause_the_program--") TrayItemSetOnEvent(-1, "pause") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. task() Func pause() ToolTip("the script has PAUSED",0,0) ;~ Sleep(1000) while 1 Sleep(50) WEnd EndFunc Func task() while 1 ToolTip("task") WEnd EndFunc Func Exit_the_program() Exit EndFunc Edited December 11, 2022 by Jos Please use an codebox for your source (<>) Link to comment Share on other sites More sharing options...
Dan_555 Posted December 11, 2022 Share Posted December 11, 2022 (edited) You have to check the tray menu item clicks in your pause function. Currently that function is started and never gets out of it. It is looping endlessly. use the TrayGetMsg() and check for the exit and pause menu's and do something in it. (either end the program or unpause it by exiting the while loop) Try out this function to see how it really works: Func pause() $e=0 while $e<100 $e=$e+1 ToolTip("the script has PAUSED") Sleep(50) WEnd ConsoleWrite ("Exit from the pause" & @crlf) EndFunc Edited December 11, 2022 by Dan_555 jacky998877 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
jacky998877 Posted December 11, 2022 Author Share Posted December 11, 2022 53 minutes ago, Dan_555 said: You have to check the tray menu item clicks in your pause function. Currently that function is started and never gets out of it. It is looping endlessly. use the TrayGetMsg() and check for the exit and pause menu's and do something in it. (either end the program or unpause it by exiting the while loop) Try out this function to see how it really works: Func pause() $e=0 while $e<100 $e=$e+1 ToolTip("the script has PAUSED") Sleep(50) WEnd ConsoleWrite ("Exit from the pause" & @crlf) EndFunc yes, this works , thx Link to comment Share on other sites More sharing options...
Solution Dan_555 Posted December 11, 2022 Solution Share Posted December 11, 2022 (edited) Sorry, but the code snippet from my previous post is not the solution that works. This is a solution that works: expandcollapse popup#include <AutoItConstants.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. Global $tray_exit=TrayCreateItem("exit_the_program--") TrayItemSetOnEvent(-1, "Exit_the_program") Global $tray_pause=TrayCreateItem("pause_the_program--") TrayItemSetOnEvent(-1, "pause") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. task() Func pause() $e=0 Opt("TrayOnEventMode", 0) while $e=0 $nmsg=TrayGetMsg() Switch $nmsg Case $tray_pause $e=1 Case $tray_exit Exit EndSwitch ToolTip("the script has PAUSED") WEnd Opt("TrayOnEventMode", 1) Return 0 EndFunc Func task() while 1 ToolTip("task") WEnd EndFunc Func Exit_the_program() Exit EndFunc Edited December 11, 2022 by Dan_555 jacky998877 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
jacky998877 Posted December 12, 2022 Author Share Posted December 12, 2022 12 hours ago, Dan_555 said: Sorry, but the code snippet from my previous post is not the solution that works. This is a solution that works: expandcollapse popup#include <AutoItConstants.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. Global $tray_exit=TrayCreateItem("exit_the_program--") TrayItemSetOnEvent(-1, "Exit_the_program") Global $tray_pause=TrayCreateItem("pause_the_program--") TrayItemSetOnEvent(-1, "pause") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. task() Func pause() $e=0 Opt("TrayOnEventMode", 0) while $e=0 $nmsg=TrayGetMsg() Switch $nmsg Case $tray_pause $e=1 Case $tray_exit Exit EndSwitch ToolTip("the script has PAUSED") WEnd Opt("TrayOnEventMode", 1) Return 0 EndFunc Func task() while 1 ToolTip("task") WEnd EndFunc Func Exit_the_program() Exit EndFunc the previous one is a good one , but this one is even better .thx Dan_555 1 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