Jump to content

[Resolved] Adding Items Dynamically in the GUI from the User POV


Recommended Posts

  • Moderators

xeroTechnologiesLLC,

A new version that also allows you to delete menu items: :)

#region

    #include <guiconstantsex.au3>
    #include <windowsconstants.au3>
    #include <staticconstants.au3>
    #include <guitreeview.au3>
    #include <guilistview.au3>

    Global $aUserItems[2] = [0, 0], $hTreeView

    ; Create an array to hold the menu items when created
    Global $aMenuItems[1][2] = [[0]]

    ; Declare ini file
    $sIni = @ScriptDir & "menu.ini"

    ; Create GUI
    $hGUI = GUICreate("Test", 500, 500)

    ; Add the static menu
    Global $mFileMenu = GUICtrlCreateMenu("&File")
    Global $mExitItem = GUICtrlCreateMenuItem("E&xit", $mFileMenu)
    Global $mHelpMenu = GUICtrlCreateMenu("&Help")
    Global $mAboutItem = GUICtrlCreateMenuItem("&About", $mHelpMenu)

    $hButton_Ins = GUICtrlCreateButton("Show User Menus", 10, 10, 120, 30)
    $hButton_Rem = GUICtrlCreateButton("Remove User Menus", 10, 50, 120, 30)

    $hButton_Add = GUICtrlCreateButton("Add User Menu Item", 10, 90, 120, 30)

    GUISetState()

#endregion

While 1

    ; Get the control ID
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $mExitItem
            Exit
        Case $hButton_Ins
            ; Get the first and last ControlID created from the user menus
            $aUserItems = _Fill_Menu(0, "UserMenu")
        Case $hButton_Rem
            ; Delete all the user menus
            For $i = $aUserItems[0] To $aUserItems[1]
                GUICtrlDelete($i)
            Next
        Case $hButton_Add
            _Add_User_Items("UserMenu")
        Case $mAboutItem
            MsgBox(0, "Hi", "Hope you find this interesting")
        Case Else
            ; Loop through the array to see if it is a menuitem controlID
            For $i = 1 To $aMenuItems[0][0]
                If $aMenuItems[$i][0] = $iMsg Then
                    ; It is!
                    MsgBox(0, "Menu", "You clicked: " & @CRLF & $aMenuItems[$i][1] & @CRLF & @CRLF & _
                                "Which means we will run: " & @CRLF & IniRead($sIni, "Links", StringReplace($aMenuItems[$i][1], " ", "_"), "Error"))
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

Func _Fill_Menu($hCID, $sText)

    Local $aCID[2]

    ; This si the first ControlID we create
    $aCID[0] = GUICtrlCreateDummy()
    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now either create a further submenu or a menuitem
        For $i = 1 To $aMenu[0][0]
            If StringInStr($aMenu[$i][0], "Item") Then
                ; Increase the count of menuitems
                $aMenuItems[0][0] += 1
                ; Increase the array size by adding a new element
                ReDim $aMenuItems[$aMenuItems[0][0] + 1][2]
                ; Add the ControlID and text to the newly created array element
                $aMenuItems[$aMenuItems[0][0]][0] = GUICtrlCreateMenuItem(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                $aMenuItems[$aMenuItems[0][0]][1] = StringReplace($aMenu[$i][1], "_", " ")
            Else
                ; Create menu
                If $hCID Then
                    ; It is a submenu
                    $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                Else
                    ; It is a top level menu
                    $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "))
                EndIf
                ; Fill menu - note this is a recursive call and we need to take care
                _Fill_Menu($aMenu[$i][0], $aMenu[$i][1])
            EndIf
        Next
    EndIf
    ; And this is the last ControlID we create
    $aCID[1] = GUICtrlCreateDummy()

    Return $aCID

EndFunc   ;==>_Fill_Menu

Func _Add_User_Items($sText)

    ; Create child GUI
    $hGUI_Add = GUICreate("Pilot Currency Check", 400, 400, 50, -50, -1, $WS_EX_MDICHILD, $hGUI)

    ; Create a treeview
    GUICtrlCreateLabel("", 10, 10, 200, 180, $SS_BLACKFRAME)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $hTreeView = GUICtrlCreateTreeView(20, 20, 180, 160);, $WS_BORDER)
    $hTV_Item = $hTreeView

    ; Create a ListView
    $hListView = GUICtrlCreateListView("", 10, 210, 200, 180, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_AddColumn($hListView, "Key", 0)
    _GUICtrlListView_AddColumn($hListView, "Value", 183)

    ; Fill the treeview with the menu structure
    _Fill_TV_LV($hTreeView, $hListView, $sText)

    ; Create other controls
    GUICtrlCreateLabel("Enter menu item text", 220, 10, 160, 20)
    $hInput_Item = GUICtrlCreateInput("", 220, 40, 160, 20)
    GUICtrlCreateLabel("Enter link", 220, 80, 160, 20)
    $hInput_Link = GUICtrlCreateInput("", 220, 100, 160, 20)
    $hButton_Addition = GUICtrlCreateButton("Add to menu", 290, 150, 100, 30)

    $hButton_Deletion = GUICtrlCreateButton("Delete from menu", 290, 350, 100, 30)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton_Addition
                ; Do we have user input
                If GUICtrlRead($hInput_Item) <> "" And GUICtrlRead($hInput_Link) <> "" Then
                    ; Read the selected menu from the treeview
                    $sSection = StringReplace(_GUICtrlTreeView_GetText($hTreeView, GUICtrlRead($hTreeView)), " ", "_")
                    ; Get the item count
                    $aItems = IniReadSection($sIni, $sSection)
                    $iIndex = $aItems[0][0] + 1
                    ; Write the new item
                    $sItem = StringReplace(GUICtrlRead($hInput_Item), " ", "_")
                    IniWrite($sIni, $sSection, "Item" & $iIndex, $sItem)
                    ; Write the link
                    IniWrite($sIni, "Links", $sItem, GUICtrlRead($hInput_Link))
                    ExitLoop
                EndIf
            Case $hButton_Deletion
                ; Read the hidden menukey value from the ListView selection
                $sText = GUICtrlRead(GUICtrlRead($hListView))
                $aSplit = StringSplit($sText, "|")
                $aMenu_Item = StringSplit($aSplit[1], "")
                ; Delete the item entry in the menu
                IniDelete($sIni, $aMenu_Item[1], $aMenu_Item[2])
                ; And delete the link
                IniDelete($sIni, "Links", $aSplit[2])
                ExitLoop
        EndSwitch

    WEnd

    ; Delete GUI
    GUIDelete($hGUI_Add)
    ; Delete all the user menus
    For $i = $aUserItems[0] To $aUserItems[1]
        GUICtrlDelete($i)
    Next
    ; Reset menu
    $aUserItems = _Fill_Menu(0, "UserMenu")

EndFunc   ;==>_Add_User_Items

Func _Fill_TV_LV($hTV_Item, $hLV, $sText)

    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now run through menu structure
        For $i = 1 To $aMenu[0][0]
            If StringInStr($aMenu[$i][0], "Item") Then
                GUICtrlCreateListViewItem(StringReplace(_GUICtrlTreeView_GetText($hTreeView, $hTV_Item), " ", "_") & "" & $aMenu[$i][0] & "|" & $aMenu[$i][1], $hLV)
            Else
                ; Create TreeViewItem
                $hTV_NewItem = GUICtrlCreateTreeViewItem(StringReplace($aMenu[$i][1], "_", " "), $hTV_Item)
                ; Fill TV - note this is a recursive call and we need to take care
                _Fill_TV_LV($hTV_NewItem, $hLV, $aMenu[$i][1])
            EndIf
        Next
    EndIf

EndFunc   ;==>_Fill_TV

M23

Edited by Melba23
Typo

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

xeroTechnologiesLLC,

Too cold for golf and no flying - so you get a version that allows you to add and delete menus as well as items. :)

#region

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <StaticConstants.au3>
    #include <GuiTreeView.au3>
    #include <GUIListview.au3>

    Global $aUser_IDs[2] = [0, 0], $hTreeView_Item, $hTreeView_Menu, $hListView

    ; Create arrays to hold the menus and menu items when created
    Global $aUser_Menus[1][2] = [[0]], $aMenuItems[1][2] = [[0]]

    ; Declare ini file
    $sIni = @ScriptDir & "menu.ini"

    ; Create GUI
    $hGUI = GUICreate("Test", 500, 500)

    ; Add the static menu
    Global $mFileMenu = GUICtrlCreateMenu("&File")
    Global $mExitItem = GUICtrlCreateMenuItem("E&xit", $mFileMenu)
    Global $mHelpMenu = GUICtrlCreateMenu("&Help")
    Global $mAboutItem = GUICtrlCreateMenuItem("&About", $mHelpMenu)

    $hButton_Ins = GUICtrlCreateButton("Show User Menus", 10, 10, 120, 30)
    $hButton_Rem = GUICtrlCreateButton("Remove User Menus", 10, 50, 120, 30)

    $hButton_Add = GUICtrlCreateButton("Amend User Menus", 10, 90, 120, 30)

    GUISetState()

#endregion

While 1

    ; Get the control ID
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $mExitItem
            Exit
        Case $hButton_Ins
            ; Get the first and last ControlID created from the user menus
            $aUser_IDs = _Fill_Menu(0, "User_Menu")
        Case $hButton_Rem
            ; Delete all the user menus
            For $i = $aUser_IDs[0] To $aUser_IDs[1]
                GUICtrlDelete($i)
            Next
        Case $hButton_Add
            _Amend_User_Menus("User_Menu")
        Case $mAboutItem
            MsgBox(0, "Hi", "Hope you find this interesting")
        Case Else
            ; Loop through the array to see if it is a menuitem controlID
            For $i = 1 To $aMenuItems[0][0]
                If $aMenuItems[$i][0] = $iMsg Then
                    ; It is!
                    MsgBox(0, "Menu", "You clicked: " & @CRLF & $aMenuItems[$i][1] & @CRLF & @CRLF & _
                                "Which means we will run: " & @CRLF & IniRead($sIni, "Links", StringReplace($aMenuItems[$i][1], " ", "_"), "Error"))
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

Func _Fill_Menu($hCID, $sText)

    Local $aCID[2]

    ; This si the first ControlID we create
    $aCID[0] = GUICtrlCreateDummy()
    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now either create a further submenu or a menuitem
        For $i = 1 To $aMenu[0][0]
            If StringInStr($aMenu[$i][0], "Item") Then
                ; Increase the count of menuitems
                $aMenuItems[0][0] += 1
                ; Increase the array size by adding a new element
                ReDim $aMenuItems[$aMenuItems[0][0] + 1][2]
                ; Add the ControlID and text to the newly created array element
                $aMenuItems[$aMenuItems[0][0]][0] = GUICtrlCreateMenuItem(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                $aMenuItems[$aMenuItems[0][0]][1] = StringReplace($aMenu[$i][1], "_", " ")
            Else
                ; Create menu
                If $hCID Then
                    ; It is a submenu
                    $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "), $hCID)
                Else
                    ; It is a top level menu
                    $aMenu[$i][0] = GUICtrlCreateMenu(StringReplace($aMenu[$i][1], "_", " "))
                EndIf
                $aUser_Menus[0][0] += 1
                ReDim $aUser_Menus[$aUser_Menus[0][0] + 1][2]
                $aUser_Menus[$aUser_Menus[0][0]][0] = $sText
                $aUser_Menus[$aUser_Menus[0][0]][1] = $aMenu[$i][1]
                ; Fill menu - note this is a recursive call and we need to take care
                _Fill_Menu($aMenu[$i][0], $aMenu[$i][1])
            EndIf
        Next
    EndIf
    ; And this is the last ControlID we create
    $aCID[1] = GUICtrlCreateDummy()

    Return $aCID

EndFunc   ;==>_Fill_Menu

Func _Amend_User_Menus($sText)

    ; Create child GUI
    $hGUI_Add = GUICreate("Amend User Menus", 400, 260, 50, 150, -1, $WS_EX_MDICHILD, $hGUI)

    $hTab = GUICtrlCreateTab(10, 10, 380, 200)

    $hTab_0 = GUICtrlCreateTabItem("Add Menu Item")

    ; Create a treeview
    GUICtrlCreateLabel("", 20, 40, 170, 160, $SS_BLACKFRAME)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $hTreeView_Item = GUICtrlCreateTreeView(30, 50, 150, 140)
    $hTV_Item_Item = GUICtrlCreateTreeViewItem("User_Menu", $hTreeView_Item)

    ; Create other controls
    GUICtrlCreateLabel("<---", 200, 40, 20, 20)
    GUICtrlCreateLabel("Select menu to hold item", 220, 40, 160, 20)
    GUICtrlCreateLabel("Enter menu item text", 220, 70, 160, 20)
    $hInput_Item = GUICtrlCreateInput("", 220, 90, 160, 20)
    GUICtrlCreateLabel("Enter link", 220, 120, 160, 20)
    $hInput_Link = GUICtrlCreateInput("", 220, 140, 160, 20)
    $hButton_Addition_Item = GUICtrlCreateButton("Add Item to menu", 220, 170, 160, 30)

    $hTab_1 = GUICtrlCreateTabItem("Delete Menu Item")

    ; Create a ListView
    $hListView = GUICtrlCreateListView("", 20, 40, 170, 160, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_AddColumn($hListView, "Key", 0)
    _GUICtrlListView_AddColumn($hListView, "Value", 153)

    ; Create other controls
    GUICtrlCreateLabel("<---", 200, 40, 20, 20)
    GUICtrlCreateLabel("Select item to delete", 220, 40, 160, 20)
    $hButton_Deletion_Item = GUICtrlCreateButton("Delete from menu", 220, 170, 160, 30)

    $hTab_2 = GUICtrlCreateTabItem("Add/Delete Menu")

    ; Create a treeview
    GUICtrlCreateLabel("", 20, 40, 170, 160, $SS_BLACKFRAME)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $hTreeView_Menu = GUICtrlCreateTreeView(30, 50, 150, 140)
    $hTV_Item_Menu = GUICtrlCreateTreeViewItem("User_Menu", $hTreeView_Menu)

    ; Create other controls
    GUICtrlCreateLabel("<---", 200, 40, 20, 20)
    GUICtrlCreateLabel("Select menu", 220, 40, 160, 20)
    GUICtrlCreateLabel("Enter new menu text", 220, 70, 160, 20)
    $hInput_Menu = GUICtrlCreateInput("", 220, 90, 160, 20)
    $hButton_Add_Menu = GUICtrlCreateButton("Add new menu", 220, 130, 160, 30)
    $hButton_Delete_Menu = GUICtrlCreateButton("Delete selected menu", 220, 170, 160, 30)

    GUICtrlCreateTabItem("")

    ; Fill the treeview s and listview with the menu structure
    _Fill_TV_LV($hTV_Item_Item, $hTV_Item_Menu, $hListView, $sText)

    $hButton_Close = GUICtrlCreateButton("Close", 310, 220, 80, 30)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hButton_Close
                ExitLoop
            Case $hButton_Addition_Item
                ; Do we have user input
                If GUICtrlRead($hInput_Item) <> "" And GUICtrlRead($hInput_Link) <> "" Then
                    ; Read the selected menu from the treeview
                    $sSection = StringReplace(_GUICtrlTreeView_GetText($hTreeView_Item, GUICtrlRead($hTreeView_Item)), " ", "_")
                    ; Get index
                    $iIndex = _GetNumber($sSection, "Item")
                    ; Write the new item
                    $sItem = StringReplace(GUICtrlRead($hInput_Item), " ", "_")
                    IniWrite($sIni, $sSection, "Item" & $iIndex, $sItem)
                    ; Write the link
                    IniWrite($sIni, "Links", $sItem, GUICtrlRead($hInput_Link))
                    ; Reset the menus
                    _Reset_Menus()
                EndIf
            Case $hButton_Deletion_Item
                ; Read the hidden menukey value from the ListView selection
                $sText = GUICtrlRead(GUICtrlRead($hListView))
                $aSplit = StringSplit($sText, "|")
                $aMenu_Item = StringSplit($aSplit[1], "")
                ; Delete the item entry in the menu
                IniDelete($sIni, $aMenu_Item[1], $aMenu_Item[2])
                ; And delete the link
                IniDelete($sIni, "Links", $aSplit[2])
                ; Now renumber the remaining items
                _Renumber($aMenu_Item[1])
                ; Reset the menus
                _Reset_Menus()
            Case $hButton_Add_Menu
                If GUICtrlRead($hInput_Menu) <> "" Then
                    ; Get host menu
                    $sHostMenu = StringReplace(_GUICtrlTreeView_GetText($hTreeView_Menu, GUICtrlRead($hTreeView_Menu)), " ", "_")
                    ; Get index
                    $iIndex = _GetNumber($sHostMenu, "Menu")
                    ; Add new menu
                    $sMenu = StringReplace(GUICtrlRead($hInput_Menu), " ", "_")
                    IniWrite($sIni, $sHostMenu, "Menu" & $iIndex, $sMenu)
                    ; Reset the menus
                    _Reset_Menus()
                EndIf
            Case $hButton_Delete_Menu
                ; Get menu
                $sDelMenu = StringReplace(_GUICtrlTreeView_GetText($hTreeView_Menu, GUICtrlRead($hTreeView_Menu)), " ", "_")
                ; Are there any entries in the ini file
                $aitems = IniReadSection($sIni, $sDelMenu)
                If Not @error Then
                    MsgBox(0, "Error", "Cannot delete menu as items remain within it")
                Else
                    ; Find parent menu
                    $iIndex = _ArraySearch($aUser_Menus, $sDelMenu, 0, 0, 0, 0, 1, 1)
                    $sParentMenu = $aUser_Menus[$iIndex][0]
                    ; Delete menu
                    IniDelete($sIni, $sDelMenu)
                    ; Delete menu from parent
                    $aItems = IniReadSection($sIni, $sParentMenu)
                    $iIndex = _ArraySearch($aItems, $sDelMenu, 0, 0, 0, 0, 1, 1)
                    $sKey = $aItems[$iIndex][0]
                    IniDelete($sIni, $sParentMenu, $sKey)
                    ; Now renumber the remaining items
                    _Renumber($sParentMenu)
                    ; Reset the menus
                    _Reset_Menus()
                EndIf
        EndSwitch

    WEnd

    ; Delete GUI
    GUIDelete($hGUI_Add)

EndFunc   ;==>_Amend_User_Menus

Func _GetNumber($sSection, $sText)

    ; Read section
    $aItems = IniReadSection($sIni, $sSection)
    ; if section does not exist
    If @error Then
        Return 1
    EndIf
    ; Set count to 1
    $iCount = 1
    ; Increase count to next available number
    For $i = 1 To $aItems[0][0]
        If StringInStr($aItems[$i][0], $sText) Then
            $iCount += 1
        EndIf
    Next
    ; Return the value
    Return $iCount

EndFunc

Func _Renumber($sSection)

    $aItems = IniReadSection($sIni, $sSection)
    If @error Then
        Return
    EndIf
    ; Set start counts
    $iMenu = 1
    $iItem = 1
    ; Renumber keys
    For $i = 1 To $aItems[0][0]
        If StringInStr($aItems[$i][0], "Menu") Then
            $aItems[$i][0] = "Menu" & $iMenu
            $iMenu += 1
        Else
            $aItems[$i][0] = "Item" & $iItem
            $iItem += 1
        EndIf
    Next
    ; Rewrite section
    IniWriteSection($sIni, $sSection, $aItems)

EndFunc

Func _Reset_Menus()

    $hWnd = GUISwitch($hGUI)
    
    ; Delete all the user menus
    For $i = $aUser_IDs[0] To $aUser_IDs[1]
        GUICtrlDelete($i)
    Next
    ; Reset menu
    $aUser_IDs = _Fill_Menu(0, "User_Menu")
    ; Reset dialog
    _GUICtrlTreeView_DeleteAll($hTreeView_Item)
    $hTV_Item_Item = GUICtrlCreateTreeViewItem("User_Menu", $hTreeView_Item)
    _GUICtrlTreeView_DeleteAll($hTreeView_Menu)
    $hTV_Item_Menu = GUICtrlCreateTreeViewItem("User_Menu", $hTreeView_Menu)
    _GUICtrlListView_DeleteAllItems($hListView)

    _Fill_TV_LV($hTV_Item_Item, $hTV_Item_Menu, $hListView, "User_Menu")

    GUISwitch($hWnd)

EndFunc

Func _Fill_TV_LV($hTV_Item_Item, $hTV_Item_Menu, $hLV, $sText)

    ; Read next level down
    $aMenu = IniReadSection($sIni, $sText)
    If Not @error Then
        ; Now run through menu structure
        For $i = 1 To $aMenu[0][0]
            If StringInStr($aMenu[$i][0], "Item") Then
                GUICtrlCreateListViewItem(StringReplace(_GUICtrlTreeView_GetText($hTreeView_Item, $hTV_Item_Item), " ", "_") & "" & $aMenu[$i][0] & "|" & $aMenu[$i][1], $hLV)
            Else
                ; Create TreeViewItem
                $hTV_NewItem_Item = GUICtrlCreateTreeViewItem(StringReplace($aMenu[$i][1], "_", " "), $hTV_Item_Item)
                $hTV_NewItem_Menu = GUICtrlCreateTreeViewItem(StringReplace($aMenu[$i][1], "_", " "), $hTV_Item_Menu)
                ; Fill TV - note this is a recursive call and we need to take care
                _Fill_TV_LV($hTV_NewItem_Item, $hTV_NewItem_Menu, $hLV, $aMenu[$i][1])
            EndIf
        Next
    EndIf

    _GUICtrlTreeView_Expand($hTreeView_Item)
    _GUICtrlTreeView_Expand($hTreeView_Menu)



EndFunc   ;==>_Fill_TV

Have fun! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Started work on implimenting your code into my main project and got most of the errors wrenched out except one.

on the following function code block:

Func _Add_User_Items($sText)
    ; Create child GUI
    $hGUI_Add = GUICreate("Add Items", 400, 400, 50, -50, -1, $WS_EX_MDICHILD, $FRMtoolbox)
    ; Create a treeview
    GUICtrlCreateLabel("", 10, 10, 200, 380, $SS_BLACKFRAME)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $hTreeView = GUICtrlCreateTreeView(20, 20, 180, 380);, $WS_BORDER)
    $hTV_Item = $hTreeView
    ; Fill the treeview with the menu structure
    _Fill_TV($hTreeView, $sText)
    ; Create other controls
    GUICtrlCreateLabel("Enter menu item text", 220, 10, 160, 20)
    $hInput_Item = GUICtrlCreateInput("", 220, 40, 160, 20)
    GUICtrlCreateLabel("Enter link", 220, 80, 160, 20)
    $hInput_Link = GUICtrlCreateInput("", 220, 100, 160, 20)
    $hButton_Addition = GUICtrlCreateButton("Add to menu", 310, 150, 80, 30)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton_Addition
                ; Do we have user input
                If GUICtrlRead($hInput_Item) <> "" And GUICtrlRead($hInput_Link) <> "" Then
                    ; Read the selected menu from teh treeview
                    $sSection = StringReplace(_GUICtrlTreeView_GetText($hTreeView, GUICtrlRead($hTreeView)), " ", "_")
                    ; Get the item count
                    $aItems = IniReadSection($sIni, $sSection)
                    $iIndex = $aItems[0][0] + 1
                    ; Write the new item
                    $sItem = StringReplace(GUICtrlRead($hInput_Item), " ", "_")
                    IniWrite($sIni, $sSection, "Item" & $iIndex, $sItem)
                    ; Write the link
                    IniWrite($sIni, "Links", $sItem, GUICtrlRead($hInput_Link))
                    ExitLoop
                EndIf
        EndSwitch
    WEnd
    ; Delete GUI
    GUIDelete($hGUI_Add)
    ; Delete all the user menus
    For $i = $aUserItems[0] To $aUserItems[1]
        GUICtrlDelete($i)
    Next
    ; Reset menu
    $aUserItems = _Fill_Menu(0, "UserMenu")
EndFunc   ;==>_Add_User_Items

...I am getting the error "Subscript used with non-Array variable on the line:

$iIndex = $aItems[0][0] + 1

...when I click the Add Item button.

Any suggestions what would be causing this error?

Thanks in advance.

Link to comment
Share on other sites

mark this one as [Resolved].

The code provided above, when tweaked for my particular project, worked flawlessly and I would highly thank Melba23 for the assist. I learned a lot and now have to go in and impliment the same proceedure to all the menu options and we are considering redoing the entire menu bar in this dynamic fashion for a later version.

Thanks for all the help. On to the next challenge on this project!

:);)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...