dinodod Posted January 13, 2007 Posted January 13, 2007 (edited) ok, this one is really getting to me. What I am trying to do is build a dynamic menu. I want all my menu items to be hosted in an INI file (Or XML if I knew how to properly use XML with autoit but I haven't seen anything easy). This allows me to manage the menu without any coding in autoit The problem is that my dymanic menu isn't very dynamic. I need to set the variable in frnt of the GUIBUTTON to be different for each menu item or else I wil run into issues when trying to determine which button was pressed. So I have the following. Any thoughts? INI FILE -------------------- [Menu1] App1=test1 App2=test2 App3=test3 CODE -------------------- expandcollapse popup#include <GUIConstants.au3> Dim $Item $gui=GUICreate("Background", 260, 150) GUISetBkColor(0xEFEBDE) GUISetFont(9, 300) $tab=GUICtrlCreateTab (10,10, 200,100) $X = 20 $Y = 40 $X_Length = 75 $tab90=GUICtrlCreateTabitem ("Games") $Game_HL2 = GUICtrlCreateButton ("HL2", $x, $Y, $X_Length) ;Try to generate a dynamic menu here ;--------------------------------------------- $var = IniReadSection("config.ini", "games") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] ;MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) $Item & $i = GUICtrlCreateButton ("HL2", $x, $Y + 20, $X_Length) Next EndIf GUICtrlCreateTabitem (""); end tabitem definition GUISetState () ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Game_HL2 Run('Notepad.exe') ; Will Run/Open Notepad EndSelect Wend Edit: change the code color and put it in [ autoit ] tags .. Edited January 13, 2007 by JdeB Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007
dinodod Posted January 13, 2007 Author Posted January 13, 2007 I am thinking that I would have to generate a custom function to read the section and write to a seperate file which would 'build' my menu then simply INCLUDE the file afterwards?? A bit more than what I was hoping for. Am I just missing something? Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007
gnosis3d Posted January 15, 2007 Posted January 15, 2007 (edited) I am thinking that I would have to generate a custom function to read the section and write to a seperate file which would 'build' my menu then simply INCLUDE the file afterwards?? A bit more than what I was hoping for. Am I just missing something? First off, are the variables in the INI in quotes? app01="test01" app02="test02" Then just have the text of a button equal that variable (haven't tried; may be out of the limits of the software). At the top of the script, app01(etc) must have IniRead() declared for each one. AU3 $app01 = IniRead(@ProgramFilesDir & "\yoursoftware\yourini.ini", "Main", "app01", "NotFound") INI [Main] app01="test01" Edited January 15, 2007 by gnosis3d
dinodod Posted January 15, 2007 Author Posted January 15, 2007 Per the help file, I didn't need to include the quotes. Do you think it makes a difference? I'll give it a try non-the-less. Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007
wiredbits Posted January 15, 2007 Posted January 15, 2007 Per the help file, I didn't need to include the quotes. Do you think it makes a difference? I'll give it a try non-the-less. While playing one day I came up with the following expandcollapse popup#include <GuiConstants.au3> ;#include <GUIConstants.au3> $ExcommandID=0 $maxMenuItems=3 Dim $ExItems [$maxMenuItems][3] $ITEM_ID=0 $ITEM_NAME=1 $ITEM_COMMAND=2 $MenuFile="ExMenu.ini" ;Generated with Form Designer preview GUICreate("Test", 412, 297, 302, 218, $WS_OVERLAPPEDWINDOW) GUISetState(@SW_SHOW) IF ReadMenuIni() Then Main() Exit Func Main() Local $i,$x $x=$ExItems[0][0] While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop case $ExItems[1][$ITEM_ID] To $ExItems[$x][$ITEM_ID] For $i=1 To $ExItems[0][0] If $ExItems[$i][$ITEM_ID]=$msg Then ExitLoop EndIf Next;i ; MsgBox(0,"", $ExItems[$i][$ITEM_NAME] & @CRLF & $ExItems[$i][$ITEM_COMMAND]) RunCommand($ExItems[$i][$ITEM_COMMAND]) Case Else ;;; EndSwitch WEnd EndFunc Func ReadMenuIni() Local $i,$varSections,$varKeysAndValues,$retvalue $retvalue=1 If FileExists($MenuFIle) Then $ExcommandID=GUICtrlCreateMenu("Commands") $ExItems[0][0]=0 $varSections = IniReadSectionNames($MenuFile) If @error Then MsgBox(4096, "", "Trouble Reading Sections In:" &$MenuFile) $retvalue=0 Else For $i=1 To $varSections[0] $varKeysAndValues = IniReadSection($MenuFile, $varSections[$i]) If @error Then MsgBox(4096, "", "Trouble Reading Keys In: " &$MenuFile & " Section: " &$varSections[$i]) $retvalue=0 ExitLoop EndIf BuildMenu($varSections[$i],$varKeysAndValues) Next EndIf Else MsgBox(4096, "", "Unable To FInd: " &$MenuFile) $retvalue=0 EndIf Return $retvalue ENDFunc Func BuildMenu($menu,Byref $varKeysAndValues) Local $i,$nmenuID,$cnt IF $ExItems[0][0]+$varKeysAndValues[0][0]> UBound($ExItems)-1 Then $maxMenuItems+=$varKeysAndValues[0][0]+1 ReDim $ExItems[$maxMenuItems][3] EndIf $cnt=$ExItems[0][0] $nmenuID=GUICtrlCreateMenu($menu,$ExcommandID) For $i=1 To $varKeysAndValues[0][0] $cnt=$cnt+1 $nmenu=$varKeysAndValues[$i][0] IF $varKeysAndValues[$i][0]="Separator" and $varKeysAndValues[$i][1] ="True" Then $nmenu="" $nmenuID=GUICtrlCreateMenuItem($nmenu,$nmenuID) $ExItems[$cnt][$ITEM_ID]=$nmenuID $ExItems[$cnt][$ITEM_COMMAND]=$varKeysAndValues[$i][1] $ExItems[$cnt][$ITEM_NAME]=$varKeysAndValues[$i][0] Next $ExItems[0][0]=$cnt EndFunc Func RunCommand($command) Opt("RunErrorsFatal", 0) Run($command) If @error Then MsgBox(8256,"Unable To Execute",$command &@CRLF &"Check Path and/or File Name.") EndIf Opt("RunErrorsFatal", 1) EndFunc Example ini file [My Computer] Open=explorer.exe /n, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} Explore=explorer.exe /e, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} Device Manager= RunDLL32.EXE devmgr.dll DeviceManager_Execute Disconnect Mapped Drive=RunDLL32.EXE USER.DLL,wnetdisconnectdialog Map A Network Drive=RunDLL32.EXE shell32.dll,SHHelpShortcuts_RunDLL Connect System Properties=RunDLL32.EXE shell32.dll,Control_RunDLL sysdm.cpl,,0 Separator=True Restart=Shutdown.exe -r -t 00 Shut Down=shutdown.exe -s -t 00 [Contro Panell] Open=Panel=RunDLL32.EXE shell32.dll,Control_RunDLL Add Remove Programs=RunDLL32.EXE shell32.dll,Control_RunDLL appwiz.cpl,,0 Administrative Tools=Open=explorer.exe /n C:\Documents and Settings\All Users\Start Menu\Programs\Accessories\System Tools Internet Options=RunDLL32.EXE shell32.dll,Control_RunDLL inetcpl.cpl,,# Network Connections=Explorer.exe ::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
dinodod Posted January 15, 2007 Author Posted January 15, 2007 While playing one day I came up with the followingjust playing around one day eh? WOW!!!This is absolutely perfect!!!Thank you so very much! It is quite a bit more than what I was thinking needed to be done but it works!!!Thank you!!! Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007
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