tinman_72 Posted June 8, 2020 Posted June 8, 2020 Hello fellow scripters. I have a script that I am working on that creates a tray menu from entries in a .INI file. The number of entries needs to be dynamic. How do I handle the tray monitoring loop? Hopefully, this simplified version of my script demonstrates what I am looking for: Opt ( 'TrayMenuMode', 3 ) Local $iNumber = InputBox ( 'Test', 'Enter the number of tray icon menu items:' ) ; Request number of tray icon menu items from User Local $aItemLabels[$iNumber + 1] ; Create array to hold tray icon menu item labels Local $idMenuItem[$iNumber + 1] ; Create array to hold menu item handles For $iFoo = 1 to $iNumber ; Assign a label to each menu item $aItemLabels[$iFoo] = 'Item #' & String ( $iFoo ) ; Create label $idMenuItem[$iFoo] = TrayCreateItem ( $aItemLabels[$iFoo] ) ; Create handle Next ; End loop $idTrayExit = TrayCreateItem ( 'Exit' ) ; Create a way to gracefully exit While 1 ; Create loop to monitor actions taken on tray menu $iMsg = TrayGetMsg() ; Store actions taken on tray menu Switch $iMsg ; Do one of the following depending on actions taken Case $idTrayExit ; User clicked 'Exit'. Exit ; Exit ;Case $idMenuItem[x] ; How do I handle an unknown number of tray items? ; MsgBox ( 4096, 'Response', 'You clicked on ' & $aItemLabels[x] ) ; EndSwitch ; WEnd
Dan_555 Posted June 8, 2020 Posted June 8, 2020 (edited) Add case else then add a for ... next loop Opt ( 'TrayMenuMode', 3 ) Local $iNumber = InputBox ( 'Test', 'Enter the number of tray icon menu items:' ) ; Request number of tray icon menu items from User Local $aItemLabels[$iNumber + 1] ; Create array to hold tray icon menu item labels Local $idMenuItem[$iNumber + 1] ; Create array to hold menu item handles For $iFoo = 1 to $iNumber ; Assign a label to each menu item $aItemLabels[$iFoo] = 'Item #' & String ( $iFoo ) ; Create label $idMenuItem[$iFoo] = TrayCreateItem ( $aItemLabels[$iFoo] ) ; Create handle Next ; End loop $idTrayExit = TrayCreateItem ( 'Exit' ) ; Create a way to gracefully exit While 1 ; Create loop to monitor actions taken on tray menu $iMsg = TrayGetMsg() ; Store actions taken on tray menu Switch $iMsg ; Do one of the following depending on actions taken Case $idTrayExit ; User clicked 'Exit'. Exit ; Exit ;Case $idMenuItem[x] ; How do I handle an unknown number of tray items? ; MsgBox ( 4096, 'Response', 'You clicked on ' & $aItemLabels[x] ) ; case Else for $tmp=1 to $iNumber if $iMsg=$IdMenuItem[$tmp] then MsgBox (0,"Trayitem",$tmp) Next EndSwitch ; WEnd Edited June 8, 2020 by Dan_555 tinman_72 1 Some of my script sourcecode
tinman_72 Posted June 8, 2020 Author Posted June 8, 2020 Thanks! That is exactly what I needed. I love the insanely fast responses on this forum.
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