Jump to content

Problem with tray menu in TrayOnEventMode


Recommended Posts

i post a simple script for exemple, to make you understand my problem starts this script and follow my directions.

1 press "go to tray" button.

2 use tray menu and press on "start do ..". (will appear a message box "rundo start, stop with tray menu or ctrl+alt+s") wait 6 second or clik ok and do loop will stat with a useless pixelgetcolor, after..

3 use again tray menu and press on "stop do .." or "exit" u will see the tray is like frozen, but if i use the hot key ctrl+alt+s it will be stoped (after all you have pressed on traymenu first will do), so the hotkey (than use the same function like a traymenu) it work always without problem.

But the problem is more complex in reality, the traymenu not freezed when the loop is active but only when the loop is started with from there, because if I start the loop with the hotkey ctrl+alt+s and then go in the traymenu it work until the loop not start from there.

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
#include <string.au3>


; Option
Opt("WinTitleMatchMode", 4)
Opt("TrayMenuMode",1)
Opt("TrayOnEventMode",1)
Opt("GUIOnEventMode", 1)
Opt("SendKeyDelay", 200)

; HotKey
HotKeySet("^!\", "Terminate");ctrl+alt+\
HotKeySet("^!s", "RunStopDo");ctrl+alt+s

Dim $stopdo = 1

; GUI
GuiCreate("Test Gui and Tray event with do function", 360, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate")

$StartBut1 = GuiCtrlCreateButton("GO TO TRAY", 100, 35, 160, 30)
GUICtrlSetOnEvent(-1, "GoToTray")

GuiSetState()

; IDLE
While 1
  sleep(50)
WEnd
;---------GUI END ----------


Func GoToTray()

WinSetState("Test Gui and Tray event with do function", "", @SW_HIDE)
TraySetToolTip("Click for the menu")

$tray1 =  TrayCreateItem("Run do (Ctrl+Alt+s)")
TrayItemSetOnEvent(-1,"RunStopDo")
$tray01 = TrayCreateItem("")
    
$tray2 =  TrayCreateItem("Exit  (Ctrl+Alt+\)")
TrayItemSetOnEvent(-1,"Terminate")
$tray02 = TrayCreateItem("")
    
TraySetState()

sleep(100)

EndFunc


Func RunStopDo()

If BitAnd(WinGetState("Test Gui and Tray event with do function", ""), 2) Then Return

if $stopdo = 0 Then
    $stopdo = 1
    TrayItemSetText($tray1, "Start do or ctrl+alt+s")
Else
    $stopdo = 0
    sleep(200)
    RunDo() 
EndIf

EndFunc


Func RunDo()
    
TrayItemSetText($tray1, "Stop do or ctrl+alt+s")

MsgBox(4096, "", "rundo start, stop with tray menu or ctrl+alt+s", 6)
Do
    sleep(1000)
    $color = PixelGetColor(200,200) 
Until   $stopdo = 1

MsgBox(4096, "", "rundo stoped pixel color= " & $color)

Return
EndFunc


Func Terminate()
    
Exit 0
    
EndFunc
Edited by Kurtferro
Link to comment
Share on other sites

Understand that gui/tray events do not interrupt the flow of custom loops and program flow in general (although HotKey does).

Once you're in this:

Do
    sleep(1000)
    $color = PixelGetColor(200,200)    
Until    $stopdo = 1oÝ÷ Û*.q©÷öض­!ü¨»§¶Ú!j÷«zÊhȯz¢þÚÚË*.².ÚeiDz¢êêº]¢Ê&zËn}øiùZ+,zÚ®¢×(u觲'^¶¦j)âvW¥¢ZºÚ"µÍY   ÌÍÜÝÜÈ    ÉÝÈH[    ÌÍØÛÛÜH^[Ù]ÛÛÜ
HÛY
L
Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

I said the MAIN LOOP.

; IDLE
While 1
  sleep(50)
WEnd

to

; IDLE
While 1
If $stopdo <> 1 Then $color = PixelGetColor(200,200)    
Sleep(1000)
WEnd

Then

Func RunStopDo()

If BitAnd(WinGetState("Test Gui and Tray event with do function", ""), 2) Then Return

if $stopdo = 0 Then
    $stopdo = 1
    TrayItemSetText($tray1, "Start do or ctrl+alt+s")
    MsgBox(4096, "", "rundo stoped pixel color= " & $color)
Else
    $stopdo = 0
    TrayItemSetText($tray1, "Stop do or ctrl+alt+s")
    MsgBox(4096, "", "rundo start, stop with tray menu or ctrl+alt+s", 6)
;~   sleep(200)
;~   RunDo()    
EndIf

EndFunc

And you also need

Global $tray1, $tray2, $color
at the top of your script.

"be smart, drink your wine"

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