Jump to content

Clearing the Event queue


Unsigned
 Share

Recommended Posts

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

.

Link to comment
Share on other sites

  • Moderators

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! :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :graduated:

Edited by Spiff59
Link to comment
Share on other sites

  • Moderators

UCL.

Missed that sorry. :graduated:

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:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

@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 :graduated: ) 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 by Unsigned

.

Link to comment
Share on other sites

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

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

.

Link to comment
Share on other sites

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

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

.

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