Unsigned Posted September 28, 2011 Share Posted September 28, 2011 (edited) Here's a small script to illustrate the problem. Run it, right-click the tray and click "A". Then while the MsgBox() is STILL displayed (don't click OK), click "B". Then click OK on A's MsgBox(). You will then see B's MsgBox() following it. Even though the B menu item was deleted by A. How can the queue be cleared by A to prevent an event being generated for a now non-existent B? Opt("TrayMenuMode", 11) Opt("TrayOnEventMode", 1) ; Enable tray events TraySetClick(16) ; menu on right-click Global $a_item = TrayCreateItem("A") TrayItemSetOnEvent(-1, "AE") Global $b_item = TrayCreateItem("B") TrayItemSetOnEvent(-1, "BE") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitE") TraySetState() Func ExitE() Exit EndFunc Func AE() MsgBox(0, "AE", "A was clicked.") TrayItemDelete($b_item) ; Any way to clear queue here? EndFunc Func BE() MsgBox(0, "BE", "B was clicked.") EndFunc While 1 Sleep(250) WEnd Exit Edited September 28, 2011 by UCL . Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2011 Moderators Share Posted September 28, 2011 UCL, There are a couple of threads discussing this in the past - here is one to which I contributed, although my idea is apparently not really the way to do it! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Unsigned Posted September 28, 2011 Author Share Posted September 28, 2011 I saw that one, however it deals with the message loop scenario, while in this case I'm dealing with events. (See "TrayOnEventMode") . Link to comment Share on other sites More sharing options...
Spiff59 Posted September 28, 2011 Share Posted September 28, 2011 (edited) A shot in the dark, this... Would the following clear the event queue, and not destroy previously defined on-event function assignments? Opt("TrayOnEventMode",0) Opt("TrayOnEventMode",1) Edit: I got off my butt, and tested it. It does a whole lot of nothing Edited September 28, 2011 by Spiff59 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2011 Moderators Share Posted September 28, 2011 UCL. Missed that sorry. To make up for it here are 2 ways to do what you want - first the obvious way: Opt("TrayMenuMode", 11) Opt("TrayOnEventMode", 1) ; Enable tray events TraySetClick(16) ; menu on right-click Global $a_item = TrayCreateItem("A") TrayItemSetOnEvent(-1, "AE") Global $b_item = TrayCreateItem("B") TrayItemSetOnEvent(-1, "BE") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitE") TraySetState() Func ExitE() Exit EndFunc Func AE() TraySetClick(0) MsgBox(0, "AE", "A was clicked.") TraySetClick(16) TrayItemDelete($b_item) ; Any way to clear queue here? EndFunc Func BE() TraySetClick(0) MsgBox(0, "BE", "B was clicked.") TraySetClick(16) EndFunc While 1 Sleep(250) WEnd Exit Or more clumsily: expandcollapse popup#include <Constants.au3> Opt("TrayMenuMode", 11) Opt("TrayOnEventMode", 1) ; Enable tray events TraySetClick(16) ; menu on right-click Global $a_item = TrayCreateItem("A") TrayItemSetOnEvent(-1, "AE") Global $b_item = TrayCreateItem("B") TrayItemSetOnEvent(-1, "BE") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitE") TraySetState() Func ExitE() Exit EndFunc Func AE() _TrayState(False) MsgBox(0, "AE", "A was clicked.") _TrayState() TrayItemDelete($b_item) ; Any way to clear queue here? EndFunc Func BE() _TrayState(False) MsgBox(0, "BE", "B was clicked.") _TrayState() EndFunc While 1 Sleep(250) WEnd Exit Func _TrayState($fState = True) If $fState Then TrayItemSetState($a_item, $TRAY_ENABLE) TrayItemSetState($b_item, $TRAY_ENABLE) Else TrayItemSetState($a_item, $TRAY_DISABLE) TrayItemSetState($b_item, $TRAY_DISABLE) EndIf EndFunc Am I forgiven? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2011 Share Posted September 28, 2011 I got it to this way, disabling while A msg is present. Func AE() TrayItemSetState($b_item, 128) MsgBox(0, "AE", "A was clicked.") TrayItemDelete($b_item) TrayItemSetState($b_item, 64) ; Any way to clear queue here? EndFunc ;==>AE AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Unsigned Posted September 28, 2011 Author Share Posted September 28, 2011 (edited) @Melba23: There still exists the possibility that B could be clicked again before TraySetClick(0) is called. (I come from a low-level kernel background, and race conditions give me chills ) Nonetheless its the best example shown here. To make up for it here are 2 ways to do what you want - first the obvious way: Opt("TrayMenuMode", 11) Opt("TrayOnEventMode", 1) ; Enable tray events TraySetClick(16) ; menu on right-click Global $a_item = TrayCreateItem("A") TrayItemSetOnEvent(-1, "AE") Global $b_item = TrayCreateItem("B") TrayItemSetOnEvent(-1, "BE") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitE") TraySetState() Func ExitE() Exit EndFunc Func AE() TraySetClick(0) MsgBox(0, "AE", "A was clicked.") TraySetClick(16) TrayItemDelete($b_item) ; Any way to clear queue here? EndFunc Func BE() TraySetClick(0) MsgBox(0, "BE", "B was clicked.") TraySetClick(16) EndFunc While 1 Sleep(250) WEnd Exit Am I forgiven? M23 @JohnOne: But you're now re-enabling $b_item when it no longer exists! O.o The actual script deals with a huge (10-20) menu items which are constantly being dynamically added and deleted, so disabling each individually would be messy at best, and impossible at worst. I got it to this way, disabling while A msg is present. Func AE() TrayItemSetState($b_item, 128) MsgBox(0, "AE", "A was clicked.") TrayItemDelete($b_item) TrayItemSetState($b_item, 64) ; Any way to clear queue here? EndFunc ;==>AE Edited May 31, 2012 by Unsigned . Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2011 Share Posted September 28, 2011 I was thinking that not always would theTrayItemDelete function be present in other functions so if it were not deleted then it would be re-enabled on completion of the function. I imagine you must be keeping track of all created tray item handles, so a method of disabling all others should be possible, I guess you are using an array to "handle the handles" if you will? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Unsigned Posted September 28, 2011 Author Share Posted September 28, 2011 (edited) I guess you are using an array to "handle the handles" if you will? Correct. However, the overhead of disabling each one mitigates the point, since the entire callback executes in less time than it would take to disable every other menu item anyway. Edited September 28, 2011 by UCL . Link to comment Share on other sites More sharing options...
JohnOne Posted September 28, 2011 Share Posted September 28, 2011 Are you certain that this sort of time would be an issue? I rarely get a time above one tenth of a millisecond to disable an alphabets worth. Opt("TrayMenuMode", 11) Opt("TrayOnEventMode", 1) TraySetClick(16) Global $aTrayItems[26] For $i = 0 To 25 $aTrayItems[$i] = TrayCreateItem(Chr($i + 65)) TrayItemSetOnEvent(-1, "_TestDisableTrayItems") Next TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitE") TraySetState() While 1 Sleep(250) WEnd Func _TestDisableTrayItems() $TrayID = @TRAY_ID $Timer = TimerInit() For $i = 0 To 25 TrayItemSetState($aTrayItems[$i], 128) Next ConsoleWrite("Disable Tray Items took " & TimerDiff($Timer) & " milliseconds" & @CRLF) MsgBox(0,0,Chr($TrayID + 58)) $Timer = TimerInit() For $i = 0 To 25 TrayItemSetState($aTrayItems[$i], 64) Next ConsoleWrite("Enable Tray Items took " & TimerDiff($Timer) & " milliseconds" & @CRLF) EndFunc Func ExitE() Exit EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Unsigned Posted September 29, 2011 Author Share Posted September 29, 2011 (edited) Are you certain that this sort of time would be an issue?I rarely get a time above one tenth of a millisecond to disable an alphabets worth.Yea, that's enough. The code itself is running in a tight-loop and performance is an issue. Will have to work on that.(It'll eventually be ported to MinGW, but since I'm still working on familiarity with the Windows GUI interface, I found it easier to work out the logic in AutoIt first.) Edited May 31, 2012 by Unsigned . 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