Jump to content

ini to list and comboEX, rearrange in list, save back to ini


Recommended Posts

Please keep in mind this is just a test file, but hopefully someone will find it useful. I had to build this to test a few theories to allow the users of the program I'm building to create, alter and save their own launching macros so that was what the idea was based on, but there are obvious other uses of something like this I would imagine.

I could not find a way to allow rearranging and multiselection together hence the check box to allow rearranging. A minor inconvinience if you ask me.

The code:

#include <array.au3>
#include <Constants.au3>
#include <ComboConstants.au3>
#include <DragList_UDF.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Global $listString = ""
Global $comboString = ""
$Debug_LB = False ; Check ClassName being passed to ListBox functions, set to True and use a handle to another control to see it work
$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work
$listArray = IniReadSection("test_list.ini", "itemlist")
$comboArray = IniReadSection("test_combo.ini", "itemlist")
#Region ### START Koda GUI section ### Form=
$hMain = GUICreate("Form2", 360, 305, 428, 264)
$hListBox = GUICtrlCreateList("", 16, 16, 161, 253, BitOR($WS_BORDER, $WS_VSCROLL, $WS_TABSTOP, $LBS_NOTIFY, $LBS_EXTENDEDSEL))
$Combo1 = _GUICtrlComboBoxEx_Create($hMain, "", 192, 16, 145, 100)
  $Combo1handle = GUICtrlGetHandle($Combo1)
$saveBTN = GUICtrlCreateButton("Save", 192, 100, 100, 30)
$rearrangeChk = GUICtrlCreateCheckbox("Rearrange On", 192, 75)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; Add items to combo box
_GUICtrlComboBoxEx_InitStorage($Combo1, $comboArray[0][0] + 1, 300)
_GUICtrlComboBoxEx_BeginUpdate($Combo1)
_GUICtrlComboBoxEx_AddString($Combo1, "New")
For $iC = 1 To $comboArray[0][0]
  _GUICtrlComboBoxEx_AddString($Combo1, $comboArray[$iC][1])
Next
_GUICtrlComboBoxEx_EndUpdate($Combo1)
$placeholder = ""
While 1
$comboText = ControlGetText($hMain, "", "[CLASS:Edit; INSTANCE:1]")
if $comboText <> $placeholder Then
  $placeholder = $comboText
Switch $comboText
  case "Macro 1"
   $macro1Array = ""
   $macro1Array = IniReadSection("testMacro1.ini", "itemlist")
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   ; Add strings
   _GUICtrlListBox_BeginUpdate($hListBox)
   _GUICtrlListBox_AddString($hListBox, "New")
   For $iI = 1 To $macro1Array[0][0]
    _GUICtrlListBox_AddString($hListBox, $macro1Array[$iI][1])
   Next
   _GUICtrlListBox_EndUpdate($hListBox)
  case "Macro 2"
   $macro2Array = ""
   $macro2Array = IniReadSection("testMacro2.ini", "itemlist")
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   ; Add strings
   _GUICtrlListBox_BeginUpdate($hListBox)
   _GUICtrlListBox_AddString($hListBox, "New")
   For $iI = 1 To $macro2Array[0][0]
    _GUICtrlListBox_AddString($hListBox, $macro2Array[$iI][1])
   Next
   _GUICtrlListBox_EndUpdate($hListBox)

  case "New"
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   MsgBox(0x40000, "", "Create a new macro...")
EndSwitch
EndIf

$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $saveBTN
   switch $comboText
    case "New"
     MsgBox(0x40000, "New Macro", "Create a new macro in the .ini files...")
    Case "Macro 1"
     ; Select a few items
     $x = _GUICtrlListBox_SelItemRange($hListBox, 1, $macro1Array[0][0])
     if $x = True Then
      $listRearrange1 = _GUICtrlListBox_GetSelItemsText($hListBox)
       For $xL = 1 to $listRearrange1[0]
        IniWrite("testMacro1.ini", "itemlist", $xL, $listRearrange1[$xL])
       Next
     Else
      Sleep(100)
     EndIf
    case "Macro 2"
     ; Select a few items
     $x = _GUICtrlListBox_SelItemRange($hListBox, 1, $macro2Array[0][0])
     if $x = True Then
      $listRearrange2 = _GUICtrlListBox_GetSelItemsText($hListBox)
       For $xL = 1 to $listRearrange2[0]
        IniWrite("testMacro2.ini", "itemlist", $xL, $listRearrange2[$xL])
       Next
     Else
      Sleep(100)
     EndIf
   EndSwitch
  case $rearrangeChk
   If GUICtrlRead($rearrangeChk) = $GUI_CHECKED Then
    _DragList_SetList($hListBox, $hMain)
   Else
    _DragList_SetList($hListBox)
   EndIf
EndSwitch
WEnd

test_combo.ini

[itemlist]
1=Macro 1
2=Macro 2

testMacro1.ini (same directory as the code)

[itemlist]
1=10
2=3
3=9
4=2
5=8
6=6
7=1
8=4
9=7
10=5

testMacro2.ini(same directory as the code)

[itemlist]
1=1
2=2
3=3
4=4
5=5
6=6
7=7
8=8
9=9
10=10

How to use:

Run the code, select a macro in the combo drown down and it should populate that ini contents in the list box on the left.

Click the check box to enable rearranging.

Once you have it arranged the way you want, hit save.

You can then go to the other macro and back to the one you edited and it should have the new arrangement also.

Hope someone finds it helpful.

Thanks to BrewManNH for the assist and the many other posts I found on ComboBoxEX work.

zip has the ini files and the code file - nothing compiled.

TEST_load_array_to_list_combo.zip

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...