ederhj

Dynamic Tray-Menu

17 posts in this topic

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

Share this post


Link to post
Share on other sites



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

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

Share this post


Link to post
Share on other sites

ederhj,

Then how about reading the file each time it changes and setting the menu at that time? How often does it change? :huh:

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

ederhj,

Then how about reading the file each time it changes and setting the menu at that time? How often does it change? :huh:

M23

My problem ist not the reading, but the event BEFORE showing the Tray-Menu.

Share this post


Link to post
Share on other sites

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

every minute

Share this post


Link to post
Share on other sites

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

thank u

i'll try this

Share this post


Link to post
Share on other sites

But almost the same but another question:

Is there an event that fires when I click on die tray-bar-icon?

Thank U

Share this post


Link to post
Share on other sites

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 :

#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

Share this post


Link to post
Share on other sites

Hi,

thank U.

Nice solution.

But isn't it possible für the standard tray menu?

Thank U

Share this post


Link to post
Share on other sites

Assuming that the delay between a mouseover and a click is more than enough I would do it like this

#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

Share this post


Link to post
Share on other sites

Thanks  smile.gif

This should always work provided that the func called by the mouseover event is built to return as fast as possible

Share this post


Link to post
Share on other sites

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

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