LTJBukem Posted January 2, 2017 Share Posted January 2, 2017 (edited) Hello Guys, i've been handling a little bit with AutoIt since a few Years. But i'm a totally Newbie with Array's. This Tool i'm forwarding to is a small Traymenu from where i can start several Workstations in our Home. It should Load the params dynamicaly from an Ini-File. So far so Good with it's appearance, but the functionality isn't given. I've been searching allready 3 day's for a solution with no result and i just cant't find the error. Maybe someone could help me out. My Code: expandcollapse popup#include <MsgBoxConstants.au3> Opt("TrayMenuMode", 3) ; no default menu and items will not automatically check/uncheck when clicked ; Read file into array $aSectionHostNames = IniReadSectionNames(@ScriptDir & "\test.ini") ; Create array holding tray item Control's Global $TrayMenuHosts[UBound($aSectionHostNames)] Global $TrayMenuFunctions[4] = ['3', 'Boot', 'Shutdown', 'Restart'] Global $TrayItemHosts[UBound($TrayMenuFunctions)] ;Setting array Global $aCreateNewArray[UBound($aSectionHostNames)][UBound($TrayMenuFunctions)] ; Creating Tray Menus and Items For $i = 1 To UBound($aCreateNewArray) - 1 $TrayMenuHosts[$i] = TrayCreateMenu($aSectionHostNames[$i]) For $k = 1 To UBound($aCreateNewArray, 2) - 1 $TrayItemHosts[$k] = TrayCreateItem($TrayMenuFunctions[$k], $TrayMenuHosts[$i]) $aCreateNewArray[$i][$k] = $aSectionHostNames[$i] & $TrayMenuFunctions[$k] Next TrayCreateItem("") Next ; Creating quit item Local $idExit = TrayCreateItem("Quit") While 1 $iTrayEvent = TrayGetMsg() ; Look to see if item is clicked For $i = 1 To UBound($aCreateNewArray) - 1 For $k = 1 To UBound($aCreateNewArray, 2) - 1 If $iTrayEvent = $TrayItemHosts[$k] Then MsgBox($MB_SYSTEMMODAL, "Selected", $aSectionHostNames[$i] & $TrayMenuFunctions[$k]) ; Here i would implement code for WOL and Shutdown - r/-s ExitLoop EndIf Next Next ; exit If $iTrayEvent = $idExit Then Exit EndIf WEnd And here the Ini-File: [Sons-Gaming-PC] MACAdresse = "001122334455" Username = "Donald Duck" Password = "123456" ipadress = 192.168.2.100 [Mediacenter] MACAdresse = "66778899AABB" Username = "Donald Duck" Password = "123456" ipadress = 192.168.2.110 [Gateway] MACAdresse = "CCDDEEFF0011" Username = "Donald Duck" Password = "123456" ipadress = 192.168.2.120 I would appreciate any help. Best Regards Edited January 3, 2017 by LTJBukem Link to comment Share on other sites More sharing options...
Subz Posted January 3, 2017 Share Posted January 3, 2017 You could try something like: expandcollapse popup#include <Array.au3> #include <MsgBoxConstants.au3> Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ;~ Enable TrayOnEventMode ; Read file into array $aSectionHostNames = IniReadSectionNames(@ScriptDir & "\test.ini") ; Create array holding tray item Control's Global $TrayMenuHosts[UBound($aSectionHostNames)] Global $TrayMenuFunctions[4] = ['3', 'Boot', 'Shutdown', 'Restart'] Global $TrayItemHosts[UBound($TrayMenuFunctions)] ;Setting array Global $aCreateNewArray[0][$TrayMenuFunctions[0]] ; Creating Tray Menus and Items For $i = 1 To $aSectionHostNames[0] $TrayMenuHosts[$i] = TrayCreateMenu($aSectionHostNames[$i]) For $k = 1 To $TrayMenuFunctions[0] $TrayItemHosts[$k] = TrayCreateItem($TrayMenuFunctions[$k], $TrayMenuHosts[$i]) TrayItemSetOnEvent(-1, '_TrayFunction') _ArrayAdd($aCreateNewArray, $TrayItemHosts[$k] & '|' & $aSectionHostNames[$i] & '|' & $TrayMenuFunctions[$k]) Next TrayCreateItem("") Next ; Creating quit item Local $idExit = TrayCreateItem("Quit") TrayItemSetOnEvent(-1, "ExitScript") While 1 Sleep(100) WEnd Func _TrayFunction() Local $iTrayItem = _ArraySearch($aCreateNewArray, @TRAY_ID) If @error = 0 Then MsgBox(64, $aCreateNewArray[$iTrayItem][2] & ' ' & $aCreateNewArray[$iTrayItem][1], $aCreateNewArray[$iTrayItem][2] & ' - ' & $aCreateNewArray[$iTrayItem][1]) EndIf EndFunc Func ExitScript() Exit EndFunc ;==>ExitScript LTJBukem 1 Link to comment Share on other sites More sharing options...
LTJBukem Posted January 3, 2017 Author Share Posted January 3, 2017 Hello Subz, i Thank you for very much for your investigation. Your code helps me out of the problem i had. Absolutely Fabulous I hope i can help you guys with some thoughts and inspiration. Thank You 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