Sign in to follow this  
Followers 0
Kent

Sub Menus on the fly

2 posts in this topic

Hey guys and girls, I want to create a menu in the system tray modeled on folders so that if the folder I point it to has sub-folders, they appear in my menu as sub-menus. I have the tray menu working fine, but the example script for sub-folders assumes you already know the sub-menus you want. I will be deploying this to different offices where they will point to a folder and I will not know if they have subfolders or not, so I need the script to check that for me and create the submenus if they exist. What it is, is a folder on a shared drive with a bunch of executables in the folder. If the office I deploy it in has different groups of executables, they put them in different subfolders of the main executable folder. Any information would be greatly appreciated.

Here is what I am working with

CODE
#Include

#Include

#include

#Include

Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.

Opt("TrayOnEventMode",1)

$k = "K:\Macros\"

;$FileList = _FileListToArray($k) ;set to this folder just to test

$FileList = _FileListToArray($k,"*.mxe") ;this shows only executable macros

If @error Then

MsgBox(0, "", "No Files\Folders Found.")

Exit

EndIf

Dim $ItemList[uBound($FileList)]

;~ $ItemList[0] = UBound($FileList) - 1

For $i = 1 to UBound($FileList) - 1

$ItemList[$i] = TrayCreateItem($FileList[$i])

TrayItemSetOnEvent(-1,'MyTrayEvent')

Next

TraySetState()

While 1

Sleep(100)

WEnd

Func MyTrayEvent()

For $i = 1 to UBound($ItemList) - 1

If $ItemList[$i] = @TRAY_ID Then

; MsgBox(0,'Info',$k & $FileList[$i])

run($k & $FileList[$i] )

ExitLoop

EndIf

Next

EndFunc

And then here is the example script that does not work because I will not know the folders to use as sub menus:

CODE
#Include

#NoTrayIcon

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

$settingsitem = TrayCreateMenu("Settings")

$displayitem = TrayCreateItem("Display", $settingsitem) ;can't use this

$printeritem = TrayCreateItem("Printer", $settingsitem) ;can't use this

TrayCreateItem("")

$aboutitem = TrayCreateItem("About")

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $aboutitem

Msgbox(64,"about:","AutoIt3-Tray-sample")

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Exit

Share this post


Link to post
Share on other sites



#Include <File.au3>
#Include <Array.au3>
#Include <Constants.au3>

Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("TrayOnEventMode",1)

Dim $root = "C:\Program Files\"
;~ Dim $root = @ScriptDir & "\"
Dim $ItemList[1][2] ; trayID and item text

$DirList = _FileListToArray($root,"*",2) 
For $i = 1 to UBound($DirList) - 1
    $ItemSubmenuId = TrayCreateMenu($DirList[$i])
    $FileList = _FileListToArray($root & $DirList[$i],"*",1)
    If Not @error Then
        For $j = 1 to UBound($FileList) - 1
            $ItemText = $root & $DirList[$i] & "\" & $FileList[$j]
;~          $ItemText = $FileList[$j]
            $ItemId = TrayCreateItem($ItemText, $ItemSubmenuId)
            TrayItemSetOnEvent(-1,'MyTrayEvent')
            AddItem($ItemList, $ItemId, $ItemText)
        Next
    EndIf
Next

TraySetState()

While 1
    Sleep(100)
WEnd

Func MyTrayEvent()
    For $i = 1 to UBound($ItemList) - 1
        If $ItemList[$i][0] = @TRAY_ID Then 
            MsgBox(0,'Info',$ItemList[$i][1])
            ExitLoop
        EndIf
    Next
EndFunc
 
Func AddItem(ByRef $array, $id, $text)
    If Not IsArray($array) Then 
        Dim $array[1][2]
    Else
        ReDim $array[UBound($array)+1][2]
    EndIf
    
    $array[UBound($array)-1][0] = $id
    $array[UBound($array)-1][1] = $text
EndFunc

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