ederhj Posted April 6, 2015 Share Posted April 6, 2015 Hello, I have the problem with dynamic Tray-Menu-Items. My Issue: The Items are dynamic by reading a file. In that file there a 1-n entries. The entries can change everytime. So I want, that die Items are read at the single moment, when I click on the tray-icon. Problem: With the "TraySetOnEvent" comes to late, that means, after showing the Tray-Menu. I need an event, that fires before the Menu is shown! Who can help me? Thank U Bye Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 ederhj,The obvious solution is to read the file and create the traymenu items before you click on the tray icon. Perhaps you could use an Adlib function to get the contents into the menu at regular intervals. 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...
ederhj Posted April 6, 2015 Author Share Posted April 6, 2015 ederhj, The obvious solution is to read the file and create the traymenu items before you click on the tray icon. Perhaps you could use an Adlib function to get the contents into the menu at regular intervals. M23 How can I do it *before*? Intervalls I don't want to use. It's only necessary, when I click on the Icon in the tray-menu. Thank U Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 ederhj,Then how about reading the file each time it changes and setting the menu at that time? How often does it change? 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...
ederhj Posted April 6, 2015 Author Share Posted April 6, 2015 ederhj, Then how about reading the file each time it changes and setting the menu at that time? How often does it change? M23 My problem ist not the reading, but the event BEFORE showing the Tray-Menu. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2015 Moderators Share Posted April 6, 2015 ederhj,I know what you want to do - but I am trying to tell you that it would be easier to read the file and create the dynamic menu before you click.So I ask again: how often does this file change and if it is not too often, just use that as a trigger to create the traymenu items which will appear when you next click on the tray icon. 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...
ederhj Posted April 18, 2015 Author Share Posted April 18, 2015 every minute Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 18, 2015 Moderators Share Posted April 18, 2015 ederhj,Sounds like a perfect case for Adlib function, but as you do not want to use one you could perhaps use seangriffin's FileSystemMonitor UDF to keep an eye on the file and read it as soon it changes. Then you can recreate the tray menu and Robert is your mother's brother when you next click on the icon.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...
ederhj Posted April 19, 2015 Author Share Posted April 19, 2015 thank u i'll try this Link to comment Share on other sites More sharing options...
ederhj Posted April 19, 2015 Author Share Posted April 19, 2015 But almost the same but another question: Is there an event that fires when I click on die tray-bar-icon? Thank U Link to comment Share on other sites More sharing options...
jguinch Posted April 19, 2015 Share Posted April 19, 2015 I don't know if this way is a good one, but you can create a invisible GUI with a context menu, and use it in place of a tray menu. For this example, you have to create the "contextItems.txt" file : each line in a menu item. Then menu is reloaded only each time you click on the tray icon : expandcollapse popup#include <TrayConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> HotKeySet("{ESC}", "_Quit") Opt("TrayIconHide", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Global $sConfigFile = @ScriptDir & "\contextItems.txt" Global $idContextMenu, $hContextMenu, $aContextItems ; ############## Create an invisible GUI to create a context menu ################## $aDesktopPos = WinGetPos(_WinAPI_GetDesktopWindow() ) $hGUI = GUICreate("", 0, 0, 0, 0, 0, $WS_EX_TOOLWINDOW) $hForm = GUICreate("", 0, 0, $aDesktopPos[0] - 100, $aDesktopPos[1] - 100, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), BitOR($WS_EX_DLGMODALFRAME, $WS_EX_TOPMOST), $hGUI) ; #################################################################################### Global $idContextMenu = GUICtrlCreateContextMenu() Global $hContextMenu = GUICtrlGetHandle($idContextMenu) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_RefreshMenu") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_RefreshMenu") TraySetState() GUISetState() While 1 $msg = GUIGetMsg() If $msg = -3 Then Exit WEnd Func _RefreshMenu() For $i = 0 To UBound($aContextItems) - 1 GUICtrlDelete($aContextItems[$i]) Next $aContextItems = FileReadToArray($sConfigFile) For $i = 0 To UBound($aContextItems) - 1 $aContextItems[$i] = GUICtrlCreateMenuItem($aContextItems[$i], $idContextMenu) Next DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hContextMenu, "int", 0, "int", MouseGetPos(0), "int", MouseGetPos(1), "hwnd", $hGUI, "ptr", 0) EndFunc Func _Quit() Exit EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
ederhj Posted April 19, 2015 Author Share Posted April 19, 2015 Hi, thank U. Nice solution. But isn't it possible für the standard tray menu? Thank U Link to comment Share on other sites More sharing options...
mikell Posted April 19, 2015 Share Posted April 19, 2015 Assuming that the delay between a mouseover and a click is more than enough I would do it like this expandcollapse popup#NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) Global $sConfigFile = @ScriptDir & "\contextItems.txt", $TrayItems[1], $n TrayCreateItem("About") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TrayCreateItem("") ; Create a separator line. _FileToTray($sConfigFile) ; create items from file TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "TrayEvent") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. TraySetClick(2) ; Releasing primary mouse button While 1 Sleep(100) ; An idle loop. WEnd Func TrayEvent() Switch @TRAY_ID ; Check the last tray item identifier. Case $TRAY_EVENT_MOUSEOVER For $i = 0 To $n - 1 TrayItemDelete($TrayItems[$i]) Next _FileToTray($sConfigFile) EndSwitch EndFunc ;==>TrayEvent Func _FileToTray($File) Local $aContextItems = FileReadToArray($File) $n = UBound($aContextItems) ReDim $TrayItems[$n] For $i = 0 To $n - 1 $TrayItems[$i] = TrayCreateItem($aContextItems[$i]) Next EndFunc Func ExitScript() Exit EndFunc ;==>ExitScript Link to comment Share on other sites More sharing options...
jguinch Posted April 19, 2015 Share Posted April 19, 2015 Nice idea Mikell ! Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted April 19, 2015 Share Posted April 19, 2015 Thanks This should always work provided that the func called by the mouseover event is built to return as fast as possible Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 19, 2015 Moderators Share Posted April 19, 2015 mikell,Nice - as so often is the case when you provide a solution.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...
jguinch Posted April 19, 2015 Share Posted April 19, 2015 What compliment ! this excellent member deserves a little distinction ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF 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