dinodod Posted February 6, 2007 Share Posted February 6, 2007 (edited) Well, I did it, finally. After racking my head up against the wall till I bled, I finally made the script work.I had a need to make a menubar that could be manage completely from a text file so I didn't need to hard code anything. Well, I am happy to inform you I did it!I had some help pointing me in the direction (Credit to wiredbits) but then i ended up expanding it so i could support multiple menu items instead of just one as well as several other items.* Issues *I know some of the items do not work. i.e. the option to exit doesn't work right. It should be easy to fix, I haven't had a chance to do so yet myself.The only major issue I do have is that my array is hardcoded. I am thinking that a REDIM command will work for that but haven't yet worked on it as I have presssing issues to address elsewhere.expandcollapse popup; Need to declare my multi-dimension without declaring it 1st. Look into redim #include <GUIConstants.au3> #include <Array.au3> Dim $cnt, $MaxIDValue Dim $MyArrayMenu [50][50] $MenuFile= @ScriptDir & "\config\MenuStrip.ini" $varSections = IniReadSectionNames($MenuFile) GUICreate("Test", 412, 297, 302, 218, $WS_OVERLAPPEDWINDOW) GUISetState(@SW_SHOW) DynamicMenu() While 1 $msg = GuiGetMsg() Switch $msg Case 1 To $MaxIDValue For $l = 1 to $cnt If $MyArrayMenu [$l][0] = $msg then run($MyArrayMenu [$l][1]) If @error Then MsgBox(8256,"Unable To Execute command" &@CRLF &"Check Path and/or File Name.") EndIf endif next Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func DynamicMenu() If FileExists($MenuFIle) Then For $MenuItemTitle=1 To $varSections[0] ;Create Menu Item $nmenuID=GUICtrlCreateMenu($varSections[$MenuItemTitle]) ;Load the subitems $varKeysAndValues = IniReadSection($MenuFile, $varSections[$MenuItemTitle]) ;Submenu Generator For $i=1 To $varKeysAndValues[0][0] $cnt = $cnt + 1 ;Since there is no COUNT option to count an array length, I had to impose this instead. Some reasn I can't do $ItemID[0] to se the length $ItemID = GUICtrlCreateMenuitem ($varKeysAndValues[$i][0],$nmenuID) ; Since I am using a multi-Dimension Array, there is no function to read the max value in one of the particular arrays ; So this is my workaround. This value is used in the Case Select statement to create the loop need to match the ID's If $ItemID > $MaxIDValue Then $MaxIDValue = $ItemID endif $MyArrayMenu [$cnt][0] = $ItemID ; Put the ID into the 1st dimension $MyArrayMenu [$cnt][1] = $varKeysAndValues[$i][1] ; Place the value into the 2nd dimension Next Next EndIf EndFunc oÝ÷ Ù³ä®*b/Ûjëh×6 [File] Exit = "Exit" [Favorites] Google = "C:\Program Files\Internet Explorer\iexplore.exe" http://www.google.com Gmail = "C:\Program Files\Internet Explorer\iexplore.exe" http://www.gmail.com Video = "C:\Program Files\Internet Explorer\iexplore.exe" http://video.google.com Autoit Forums = "C:\Program Files\Internet Explorer\iexplore.exe" http://www.autoitscript.com/forum/ [Tools] Options = "options" [Help] About = "notepad" "Version Info.txt" Edited February 6, 2007 by dinodod 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 Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted February 6, 2007 Share Posted February 6, 2007 (edited) i modified the code just a tab bit, error checking, byref array.. ect tell me what you think.. :"> btw i think ubound() is what you were looking for expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> GUICreate("Test", 412, 297, 302, 218, $WS_OVERLAPPEDWINDOW) Dim $MenuFile = 'MenuStrip.ini', $MyArrayMenu[1][1] GUICtrlCreateDynamicMenu($MenuFile, $MyArrayMenu) GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case Else For $l = 1 to $MyArrayMenu[0][0];$cnt If $MyArrayMenu [$l][0] = $msg then ;run($MyArrayMenu [$l][1]) ConsoleWrite($MyArrayMenu[$l][1] &@LF) If @error Then MsgBox(8256,'error',"Unable To Execute command" &@CRLF &"Check Path and/or File Name.") EndIf endif next EndSwitch WEnd Func GUICtrlCreateDynamicMenu($MenuFIle, ByRef $MyArrayMenu) If FileExists($MenuFIle) Then Local $varSections = IniReadSectionNames($MenuFile), $MaxIDValue, $iCnt = 0 If @error Then Return SetError(2,0,-2) For $MenuItemTitle = 1 To $varSections[0] ;Create Menu Item $nmenuID = GUICtrlCreateMenu($varSections[$MenuItemTitle]) ;Load the subitems $varKeysAndValues = IniReadSection($MenuFile, $varSections[$MenuItemTitle]) If @error Then ContinueLoop ;Submenu Generator For $i = 1 To $varKeysAndValues[0][0] $iCnt = $iCnt + 1 ReDim $MyArrayMenu[$iCnt + 1][2] $ItemID = GUICtrlCreateMenuitem ($varKeysAndValues[$i][0],$nmenuID);Create the Dynamic Menu $MyArrayMenu [$iCnt][0] = $ItemID ; Put the ID into the 1st dimension $MyArrayMenu [$iCnt][1] = $varKeysAndValues[$i][1] ; Place the value into the 2nd dimension Next Next ;Put the Total amount of array in [0][0] $MyArrayMenu[0][0] = $iCnt Return SetError(0,0,1) Else Return SetError(1,0,-1) EndIf EndFunc Edited February 7, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
dinodod Posted February 7, 2007 Author Share Posted February 7, 2007 I see where you temporarly replaced the run command with ConsoleWrite. I've never been able to get ConsoleWrite to work for me. How do you see the console? UBound wil return the size of the array but what I am trying to do is actually resize the array on the fly as it's being made. REDIM will resize the array and keep it's contents (Need to read more on the subject to better understand it). I see that you are using the REDIM command in your code as well Yea, I haven't done much with error checking hyet. Because of pressing issues, I had to crack the code as quickly a possible. Since I'm working with a variety of dynamic menus right now(Menu bars and now a Treemenu), I'm focusing on the bare min. to get it done, whch means exclding a proper error checking system. Maybe I will design a dynamic error checking system as well I see where you it appears that you are setting the size of the array. Interesting. I'll need to learn that trick. ;Put the Total amount of array in [0][0] $MyArrayMenu[0][0] = $iCnt Return SetError(0,0,1) Else Return SetError(1,0,-1) EndIf Thanks for your feedback. I hope this comes handy. 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 Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 7, 2007 Share Posted February 7, 2007 (edited) Good idie! a long time ago i wanted to do somthing like this, but didn't know how, and now when i know, i forgot about this .Here is my version on this feature (engine?) - it allow to add more SubMenus and more... :expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> Opt("GuiOnEventMode", 1) Opt("RunErrorsFatal", 0) GUICreate("GUI Custom Menu", 412, 297, 302, 218, $WS_OVERLAPPEDWINDOW) GUISetOnEvent(-3, "Quit") Dim $MenuFile = @ScriptDir & '\Menu.ini', $ItemEventsArr[1][1] _GUICtrlCreateCustomMenu($MenuFile, $ItemEventsArr) GUISetState() While 1 Sleep(100) WEnd Func Quit() Exit EndFunc Func _GUICtrlCreateCustomMenu($MenuFile, ByRef $ItemEventsArr) Local $MenuID, $MenuID2, $ItemID, $iCnt = 0 $MainMenuSectArr = IniReadSection($MenuFile, "Main Menu") If Not @error Then For $iArr = 1 To $MainMenuSectArr[0][0] If StringLeft($MainMenuSectArr[$iArr][0], 8) = "Submenu," Then $MenuID = GUICtrlCreateMenu(StringTrimLeft($MainMenuSectArr[$iArr][0], 9)) $SubMenuArr = IniReadSection($MenuFile, StringTrimLeft($MainMenuSectArr[$iArr][0], 9)) If Not @error Then For $jArr = 1 To $SubMenuArr[0][0] $iCnt += 1 ReDim $ItemEventsArr[$iCnt + 1][2] If StringLeft($SubMenuArr[$jArr][0], 5) = "Item," Then $ItemID = GUICtrlCreateMenuitem(StringTrimLeft($SubMenuArr[$jArr][0], 6), $MenuID) $ItemEventsArr[$iCnt][0] = $ItemID $ItemEventsArr[$iCnt][1] = $SubMenuArr[$jArr][1] ElseIf StringLeft($SubMenuArr[$jArr][0], 8) = "Submenu," Then $MenuID2 = GUICtrlCreateMenu(StringTrimLeft($SubMenuArr[$jArr][0], 9), $MenuID) $SubSubMenuArr = IniReadSection($MenuFile, StringTrimLeft($SubMenuArr[$jArr][0], 9)) If Not @error Then For $ijArr = 1 To $SubSubMenuArr[0][0] $iCnt += 1 ReDim $ItemEventsArr[$iCnt + 1][2] If StringLeft($SubSubMenuArr[$ijArr][0], 5) = "Item," Then $ItemID = GUICtrlCreateMenuitem(StringTrimLeft($SubSubMenuArr[$ijArr][0], 6), $MenuID2) GUICtrlSetOnEvent($ItemID, "MainEvents") $ItemEventsArr[$iCnt][0] = $ItemID $ItemEventsArr[$iCnt][1] = $SubSubMenuArr[$ijArr][1] $ItemEventsArr[0][0] = $iCnt Next EndIf EndIf GUICtrlSetOnEvent($ItemID, "MainEvents") $ItemEventsArr[0][0] = $iCnt Next EndIf Next EndIf EndFunc Func MainEvents() For $iEv = 1 To $ItemEventsArr[0][0] If @GUI_CtrlId = $ItemEventsArr[$iEv][0] Then $CurentIDVal = $ItemEventsArr[$iEv][1] Select Case StringLeft($CurentIDVal, 8) = "Execute," Run(StringStripWS(StringTrimLeft($CurentIDVal, 8), 3)) If @error Then MsgBox(16, "Error - Program not found", "Can not execute an external program") Case $CurentIDVal = "Exit" Exit Case StringLeft($CurentIDVal, 7) = "MsgBox," Local $Title, $Message $TitleMsgArr = StringSplit($CurentIDVal, ",") If IsArray($TitleMsgArr) Then If $TitleMsgArr[0] >= 3 Then $Title = $TitleMsgArr[3] If $TitleMsgArr[0] >= 5 Then $Message = $TitleMsgArr[5] MsgBox(64, $Title, $Message) EndIf EndSelect ExitLoop EndIf Next EndFuncAnd the Menu.ini file must include this:[Main Menu] Submenu, File= Submenu, Favorites= Submenu, Tools= Submenu, Help= Submenu, Test= [File] Submenu, New Submenu= Item, Exit=Exit [Favorites] Item, Google = Execute, "C:\Program Files\Internet Explorer\iexplore.exe" http://www.google.com Item, Gmail = Execute, "C:\Program Files\Internet Explorer\iexplore.exe" http://www.gmail.com Item, Video = Execute, "C:\Program Files\Internet Explorer\iexplore.exe" http://video.google.com Item, Autoit Forums = Execute, "C:\Program Files\Internet Explorer\iexplore.exe" http://www.autoitscript.com/forum/ [Tools] Item, Options = options [Help] Item, About = MsgBox, Title, Version Info, Message, Version is: 1.0 [New Submenu] Item, My Program=Execute, "C:\Program Files\MyProgram\MyScript.exe" Edited February 7, 2007 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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