goss34 Posted January 12, 2015 Posted January 12, 2015 Afternoon Pros, Its been some time since i have asked for help but im struggling with this script: expandcollapse popup#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
Moderators Solution Melba23 Posted January 12, 2015 Moderators Solution Posted January 12, 2015 goss34,I would send the unwanted events to a dummy function - something like this: expandcollapse popup#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) EndFuncM23 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
goss34 Posted January 12, 2015 Author Posted January 12, 2015 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
Moderators Melba23 Posted January 12, 2015 Moderators Posted January 12, 2015 goss34,Glad I could help. That seems fine to me - after all, it works! 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
goss34 Posted January 12, 2015 Author Posted January 12, 2015 goss34, Glad I could help. That seems fine to me - after all, it works! M23 Certainly does, thanks again.
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