JWoodruff Posted September 4, 2007 Share Posted September 4, 2007 Hello Everyone, I am attempting to create a dynamic menu and I am not sure how to or if it is possible to increment the name of a variable to do so. Ultimately I want to dynamically create the variable name to call it later in a case. for example it will read from an INI file then create FileMenuItem1, FileMenuItem2 variables etc.... For $a = 1 to 20 $var = IniRead("test.ini", $a, "value","default") $type = IniRead("test.ini", $a, "type","default") if $type = "a" Then $FileMenuItem($a) = GuiCtrlCreateMenuitem ($var,$FileMenu1) Else if $type <>"default" Then $FileMenuItem($a) = GuiCtrlCreateMenuitem ($var,$FileMenu2) EndIf EndIf Next GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $FileMenuItem1 msgbox(1,"test",$FileMenuItem1) EndSelect WEnd - Woody Link to comment Share on other sites More sharing options...
Valuater Posted September 4, 2007 Share Posted September 4, 2007 Welcome to the forums.... 8) this might help expandcollapse popup#include<guiconstants.au3> Global $FileMenuItem[23] ; "1" more than the items used GUICreate("My Menu") $FileMenu1 = GUICtrlCreateMenu ("&File") ; for testing $FileMenu2 = GUICtrlCreateMenu ("&Menu") ; for testing $FileMenuItem[21] = GuiCtrlCreateMenuitem ("Test 1",$FileMenu1) $FileMenuItem[22] = GuiCtrlCreateMenuitem ("Test 2",$FileMenu2) For $a = 1 to 20 $var = IniRead("test.ini", $a, "value","default") $type = IniRead("test.ini", $a, "type","default") if $type = "a" Then $FileMenuItem[$a] = GuiCtrlCreateMenuitem ($var,$FileMenu1) ; menu or menu item??? Else if $type <>"default" Then $FileMenuItem[$a] = GuiCtrlCreateMenuitem ($var,$FileMenu2) EndIf EndIf Next GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $FileMenuItem[21] msgbox(1,"test"," do this....", 5) EndSelect WEnd Nice first try 8) Link to comment Share on other sites More sharing options...
JWoodruff Posted September 4, 2007 Author Share Posted September 4, 2007 Welcome to the forums.... 8) this might help #include<guiconstants.au3> Global $FileMenuItem[23] ; "1" more than the items used ... Thanks for the assistance! That does the trick! - Woody Link to comment Share on other sites More sharing options...
Vaner Posted September 6, 2007 Share Posted September 6, 2007 reading this topic i really tough it will fix my little issue here. i have a trayitemmenu build from a array item list 1 of the item will be get the Tray_Check state set. my issue is i cannot preset the size of the array like u do , i have no idea the number it will have before . if i do $item = TrayCreateItem it will build every item i need , but later on i need to do a trayitemgettext if i use the $item it always return the last value created , so instead i use @tray_id get my handle . but i need to change the stat of the previous check item to uncheck it. since i cannot use $item or $item[$i] to build the menu , so i just build it , but how do i extract the handle of the last check item in the menu list . i can build array of itemtext/itemhandle and search tru it , but i dont think it the best way to do it , im looking for to refresh the list same way i can reset data of a drop down menu in guictrl . i pretty sure it me missing a little dump thing ,on how to reset a trayitemlist , or build random variable for my item. so it look like this , for this menu : expandcollapse popup#include <array.au3> Global $Array[1] #Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",3); Default tray menu items (Script Paused/Exit) will not be shown. Opt("TrayOnEventMode",1) $settingsitem = TrayCreateMenu("tool") $displayitem = TrayCreateItem("Network", $settingsitem,-1,-1) ;TrayItemSetOnEvent(-1,"net") $printeritem = TrayCreateMenu("Printer", $settingsitem ,-1) printer() $exititem = TrayCreateItem("Exit",-1,1) TrayItemSetOnEvent(-1,"end") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop EndSelect sleep(10) WEnd Exit func dprinter() ;$Dprinter = "HP LaserJet 4100 Series PS" $Dprinter = TrayItemGetText(@TRAY_ID) $Printdll = ("RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n") $SetDPcmd = ($Printdll & ' "' & $Dprinter & '"') run($SetDPcmd) ;printer() ;;;;;;;;;;;;;;;;;;;;;;;trying to reset printer item menu TrayitemSetState(@TRAY_ID,$TRAY_CHECKED) EndFunc func printer() $objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colSettings = $objWMIService.ExecQuery("Select * from Win32_printer") $printerstring = "" For $objOperatingSystem in $colSettings $PcInfo = $objOperatingSystem.name $tmpPreset = $objOperatingSystem.default _Arrayadd($Array,$pcinfo) if $tmpPreset = -1 then $dfprinter = $pcinfo EndIf Next ;_ArrayDisplay($Array) for $i = 1 to UBound($Array) -1 $printerstring = $array[$i] if $printerstring = $dfprinter then TrayCreateItem ($printerstring,$printeritem , -1,-1) TrayItemSetOnEvent(-1,"dprinter") TrayitemSetState(-1,$TRAY_CHECKED) Else TrayCreateItem ($printerstring,$printeritem , -1,-1) TrayItemSetOnEvent(-1,"dprinter") endif ;MsgBox(48,"s",$printerstrin) next EndFunc Func end() Exit EndFunc ; $tmpPreset = $objOperatingSystem.default ; if $tmpPreset = -1 then ; MsgBox(48,"t",$tmpPreset) ; $printerlist = TrayCreateItem($pcinfo, $printeritem, -1,-1) ; EndIf ;MsgBox(48,"PCinfo",$pcinfo) ; MsgBox(48, "PCinfo", $tmpPreset) ; $printerlist = TrayCreateItem($pcinfo, $printeritem, -1,-1) ;TrayItemSetOnEvent(-1,"Dprinter") Any idea what i should be looking for ? 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