Jump to content

this script is not working as i wanted


Go to solution Solved by Dan_555,

Recommended Posts

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 by Jos
Please use an codebox for your source (<>)
Link to comment
Share on other sites

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 by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

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

  • Solution

Sorry, but the code snippet from my previous post is not the solution that works. 

This is a solution that works:

 

#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 by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

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:

 

#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

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