Jump to content

dealing with dynamic tray menus


Recommended Posts

Right now I have a tray menu being created dynamically according to a starting directory. It will show all the directories/sub directories and files within the starting directory, and those directories and files locations and names can change on a daily basis. When the user clicks on a menu item (file) under this menu, I need to be able to retrieve the location of the file. I know that I can use @TRAY_ID to get the text of the menu item clicked, but what if this text is in multiple locations? Is there any way to get the parent menu of this text to get a more accurate reading? One thing I can do is put the entire path to the file or folder in the menu text but that seems like a messy solution and I'm trying to avoid it.

Edited by jaywalk
Link to comment
Share on other sites

Right now I have a tray menu being created dynamically according to a starting directory. It will show all the directories/sub directories and files within the starting directory, and those directories and files locations and names can change on a daily basis. When the user clicks on a menu item (file) under this menu, I need to be able to retrieve the location of the file. I know that I can use @TRAY_ID to get the text of the menu item clicked, but what if this text is in multiple locations? Is there any way to get the parent menu of this text to get a more accurate reading? One thing I can do is put the entire path to the file or folder in the menu text but that seems like a messy solution and I'm trying to avoid it.

Just save the control IDs and paths in a 2D array when creating the menu for look up when you need it.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I thought of some sort of array lookup, but right now I'm handling events manually and passing all of these items to one event (since I don't know how the menu structure will be at design time). So if click events on each of the menu items are causing this one function to execute, how am I able to access the controlid? As I said, I can get the text of the menu item (@TRAY_ID) and then do some sort of lookup for the location, but what if the text is the exact same between two menu items? How would I access the controlid for that kind of situation?

Edited by jaywalk
Link to comment
Share on other sites

I thought of some sort of array lookup, but right now I'm handling events manually and passing all of these items to one event (since I don't know how the menu structure will be at design time). So if click events on each of the menu items are causing this one function to execute, how am I able to access the controlid? As I said, I can get the text of the menu item (@TRAY_ID) and then do some sort of lookup for the location, but what if the text is the exact same between two menu items? How would I access the controlid for that kind of situation?

At runtime, build an array containing the TRAY_ID of each item, along with it's full path. For example:
Global $avTrayItems[50][2]

; The 27th item...
$avTrayItems[26][0] = TrayCreateItem("CommonName", $MenuID)
$avTrayItems[26][1] = "\Root\Menu1\Menu2\CommonName"


; The tray event...
Func _TrayItemHit()
    ; Find item in array
    Local $iItem = _ArraySearch($avTrayItems, @TRAY_ID)
    If @error = 0 Then
        ; Get path of item from array
        Local $sPath = $avTrayItems[$iItem][1]
        MsgBox(64, "Tray Item Hit", "You clicked: " & $sPath)
    Else
        MsgBox(16, "Error", "Unhandled case:" & _
                @TAB & "@TRAY_ID = " & @TRAY_ID & " not found in list of items.")
    EndIf
EndFunc

The array contains the ID in [n][0] and the string path in [n][1]. Easy to look up from the event function.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Alright, I feel stupid now. I guess because I had multiple scripts open I misunderstood how @tray_id was being used. It makes sense that it would return the control id but I wasn't seeing it in my code due to the way I had it set up. Thanks for the example and quick responses, everything is cleared up now.

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