Sign in to follow this  
Followers 0
goss34

TrayEvent Select Statement Queueing

5 posts in this topic

Afternoon Pros,

Its been some time since i have asked for help but im struggling with this script:

#include <TrayConstants.au3> ; Required for the $TRAY_EVENT_PRIMARYDOUBLE and $TRAY_EVENT_SECONDARYUP constants.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <IE.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.

If FileExists("C:\Program Files\Company\Contact GTAS\GTAS Desktop Icon - 256x256.ico") Then
    $ProgramFiles = "C:\Program Files"
Else
    $ProgramFiles = "C:\Program Files (x86)"
EndIf

TraySetIcon($ProgramFiles & "\Company\Contact GTAS\GTAS Desktop Icon - 256x256.ico") ; Set path to icon

LaunchTray()

Func LaunchTray()

        TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; On action launch TrayEvent function
        TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "TrayEvent") ; On action launch TrayEvent function
        TraySetToolTip("Need help from GTAS? Click Me") ; Set the tray menu tooltip
        TraySetState(1) ; Show the tray menu.

        While 1
            Sleep(100) ; An idle loop.
        WEnd

EndFunc   ;==>LaunchTray

Func TrayEvent()

Switch @TRAY_ID ; Check the last tray item identifier.

        Case $TRAY_EVENT_PRIMARYUP

            Local $oIE = _IECreateEmbedded()
            $Gui = GUICreate("IT Related Issue", @DesktopWidth - 25, @DesktopHeight - 25, 0, 0, $WS_MAXIMIZE + $WS_VISIBLE + $WS_OVERLAPPEDWINDOW + $WS_EX_APPWINDOW)
            GUISetIcon($ProgramFiles & "\Company\Contact GTAS\GTAS Desktop Icon - 256x256.ico")
            GUICtrlCreateObj($oIE, 05, 05, @DesktopWidth, @DesktopHeight)
            GUICtrlSetResizing(-1, $GUI_DOCKBORDERS + $WS_MAXIMIZE)
            WinSetState($Gui, "", @SW_MAXIMIZE)
            GUISetState() ;Show GUI

            _IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")
            _IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")

            While 1
                Local $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
                        ;_IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")
                        ;_IEAction($oIE, "stop")
                EndSelect
            WEnd

            GUIDelete()

        Case $TRAY_EVENT_SECONDARYUP

            Local $oIE = _IECreateEmbedded()
            $Gui = GUICreate("IT Related Issue", @DesktopWidth - 25, @DesktopHeight - 25, 0, 0, $WS_MAXIMIZE + $WS_VISIBLE + $WS_OVERLAPPEDWINDOW + $WS_EX_APPWINDOW)
            GUISetIcon($ProgramFiles & "\Company\Contact GTAS\GTAS Desktop Icon - 256x256.ico")
            GUICtrlCreateObj($oIE, 05, 05, @DesktopWidth, @DesktopHeight)
            GUICtrlSetResizing(-1, $GUI_DOCKBORDERS + $WS_MAXIMIZE)
            WinSetState($Gui, "", @SW_MAXIMIZE)
            GUISetState() ;Show GUI

            _IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")
            _IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")

            While 1
                Local $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
                        ;_IENavigate($oIE, $ProgramFiles & "\Company\Contact GTAS\contactingGTAS.html")
                        ;_IEAction($oIE, "stop")
                EndSelect
            WEnd

            GUIDelete()

    EndSwitch

EndFunc   ;==>TrayEvent

Its working 99% fine but once the tray icon is running i can left click the icon as expected and the gui loads with the html page inside it - great. If the window is still open and i click the tray icon again nothing happens - as expected. Now i close the gui and then the gui reopens as if it remembers i clicked on the tray icon while the gui was open already. If i was to click 10 times while the gui is open as soon as i close it then it would reopen... 10 times! (each time i close the next window).

Its not a major issue for me as there should be no need to click it while its open but i want to get it working 100% correctly.

Can anyone help me out?

Thank you

Share this post


Link to post
Share on other sites



goss34,

I would send the unwanted events to a dummy function - something like this: :)

#include <TrayConstants.au3> ; Required for the $TRAY_EVENT_PRIMARYDOUBLE and $TRAY_EVENT_SECONDARYUP constants.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.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.

LaunchTray()

; Run the idle loop in the main script, not in a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
While 1
    Sleep(100) ; An idle loop.
WEnd

Func LaunchTray()

    TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; On action launch TrayEvent function
    TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "TrayEvent") ; On action launch TrayEvent function
    TraySetState(1) ; Show the tray menu.

EndFunc   ;==>LaunchTray

Func TrayEvent()

    Local Static $bPriRunning = False

    Switch @TRAY_ID ; Check the last tray item identifier.

        Case $TRAY_EVENT_PRIMARYUP

            TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Dummy") ; Set the event to fire a dummy function

            MsgBox($MB_SYSTEMMODAL, "Click", "Primary UP") ; Now run your code

            TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; And then reset the event function

        Case $TRAY_EVENT_SECONDARYUP

            MsgBox($MB_SYSTEMMODAL, "Click", "Secondary UP") ; This still shows the unwanted behaviour

    EndSwitch

EndFunc   ;==>TrayEvent

Func Dummy()

    ConsoleWrite("Dummy" & @CRLF)

EndFunc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

As ever, fixed in a few minutes after i asked for help after wasting no end of time with silly things like "If Not WinExists" etc.

M23 your example worked great and i can understand why (unusual for me).

In order to stop the same problem if they left and then right click i just reset the events for both clicks under both cases: (only did it for the primary below)

Switch @TRAY_ID ; Check the last tray item identifier.

        Case $TRAY_EVENT_PRIMARYUP

            TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Dummy") ; Set the event to fire a dummy function
            TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "Dummy") ; Set the event to fire a dummy function

            MsgBox($MB_SYSTEMMODAL, "Click", "Primary UP") ; Now run your code

            TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; And then reset the event function
            TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "TrayEvent") ; And then reset the event function

        Case $TRAY_EVENT_SECONDARYUP

            MsgBox($MB_SYSTEMMODAL, "Click", "Secondary UP") ; This still shows the unwanted behaviour

    EndSwitch

Is that the best way in your opinion M23?

Thank a lot for your help, much appreciated.

Dan

Share this post


Link to post
Share on other sites

goss34,

Glad I could help. That seems fine to me - after all, it works! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

goss34,

Glad I could help. That seems fine to me - after all, it works! :D

M23

Certainly does, thanks again.

Share this post


Link to post
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
Sign in to follow this  
Followers 0