WilliamasKumeliukas Posted July 20, 2021 Posted July 20, 2021 I need help, my goal is to import / export GUI configuration to a ini file but (I know it might sound dumb) I'm lost, I don't know about the method I should go, I never did this before unless it was linear but in this one I would need an dynamic friendly approach and so far I am able to detect the type of control at least and read/write to ini using my ini function. (P.S if your confuse or something is missing, let me know, I will explain further more later if needed but, now I need a break, took me 30mins to write this, i'm mentally exhausted by this and I'm barely able to write properly right now) expandcollapse popup#Region Includes <<<<<<<< #include <Constants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <Array.au3> #include <GuiButton.au3> #include <TreeViewConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", $GUI_DOCKAUTO) #EndRegion Includes <<<<<<<< #Region DECLARE VARIABLES FOR LATER USE Global $ConfigDir = @ScriptDir Global $hInput Global $iniFile = $ConfigDir & "\default.ini" Global $GUI ; GUI Global $Go ;RUN BUTTON Global $label[99] Global $task[99] Global $sMsg Global $sRunTasks $task[0] = "99" ; WILL BE CHANGED TO REAL NUMBER BEFORE GUI SHOW $label[0] = "99" #EndRegion DECLARE VARIABLES FOR LATER USE GUI() #Region GUI code Func GUI() #Region GUI Global $GUI = GUICreate(@ScriptName, 1013, 620) $tab = GUICtrlCreateTab(0, 0, 697, 541, -1, -1) GUICtrlSetState($tab, $GUI_ONTOP) GUICtrlCreateTabItem("Tab 1") GUICtrlCreateTabItem("") GUICtrlSetResizing(-1, 70) ;Menu items local $FileMenu = GUICtrlCreateMenu("FileMenu") local $FileImp = GUICtrlCreateMenuItem("Import / Load", $FileMenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) local $FileExp = GUICtrlCreateMenuItem("Export / Save",$FileMenu) GUICtrlCreateMenuItem("", $Filemenu, 2) ; create a separator line local $FileEx = GUICtrlCreateMenuItem("Exit",$FileMenu) local $HelpMenu = GUICtrlCreateMenu("HelpMenu") local $HelpInfo = GUICtrlCreateMenuItem("HelpInfo",$HelpMenu) GUICtrlCreateGraphic(705, 45, 300, 455, BitOR($GUI_SS_DEFAULT_GRAPHIC, $SS_WHITEFRAME, $WS_BORDER)) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFFFFF) $task[1] = GUICtrlCreateCheckbox("task 1", 710, 48, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[2] = GUICtrlCreateCheckBox("task 2", 710, 70, 260, 24, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $hInput = GUICtrlCreateInput("hInput", 710, 440, 280, 30) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlSetState(-1, $GUI_DISABLE) $task[3] = GUICtrlCreateCheckbox("task 3", 710, 95, 290, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[4] = GUICtrlCreateCheckbox("task 4", 710, 119, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[5] = GUICtrlCreateCheckbox("task 5", 710, 142, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[6] = GUICtrlCreateCheckbox("task 6", 710, 168, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[7] = GUICtrlCreateCheckbox("task 7", 710, 190, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[8] = GUICtrlCreateCheckbox("task 8", 710, 212, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[9] = GUICtrlCreateCheckbox("task 9", 710, 234, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $task[10] = GUICtrlCreateCheckbox("Task 10 (Select All)", 710, 256, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) $sRunTasks = GUICtrlCreateButton("Run", 910, 510, 80, 30) $label[1] = GUICtrlCreateLabel("label[1]:", 780, 23, 160, 18, $SS_CENTER, -1) GUICtrlSetFont(-1, 12, 800, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlCreateGroup("group 1",6,35,380,230) $label[2] = GUICtrlCreateLabel("label2:", 77, 52, 95) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing($label[1], $GUI_DOCKAUTO) $task[12] = GUICtrlCreateInput("task[12]", 125, 50, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $label[3] = GUICtrlCreateLabel("label3:",77, 90, 95) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing($label[2], $GUI_DOCKAUTO) $task[13] = GUICtrlCreateInput("task[13]", 125, 88, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $label[4] = GUICtrlCreateLabel("label4:", 77, 128, 95) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $task[14] = GUICtrlCreateInput("task[14]", 125, 126, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $label[5] = GUICtrlCreateLabel("label5:", 77, 166, 110) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $task[15] = GUICtrlCreateInput("tas[15]", 125, 164, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $label[7] = GUICtrlCreateLabel("label7:", 77, 198, 110) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $task[16] = GUICtrlCreateInput("task[16]", 125, 196, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $label[6] = GUICtrlCreateLabel("label6:", 77, 234, 101) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $task[17] = GUICtrlCreateInput("task[17]", 125, 232, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $oemfile = GUICtrlCreateButton("...", 350, 232, 30, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS sans serif", 2) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlCreateGroup("group 2",6,265,380,200) $label[8] = GUICtrlCreateLabel("label8:", 77, 282, 110, 15) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $task[11] = GUICtrlCreateInput("task[11]", 125, 280, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) For $i = UBound($task)-1 To 0 Step -1 If $task[$i] = "" Then _ArrayDelete($task, $i) EndIf Next For $i = UBound($label)-1 To 0 Step -1 If $label[$i] = "" Then _ArrayDelete($label, $i) EndIf Next $task[0] = UBound($task) $label[0] = UBound($label) GUISetState(@SW_SHOW, $GUI) #EndRegion GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $FileEx Exit Case $FileImp _ImportIni() Case $FileExp _ExportIni() Case $task[10] If GUICtrlRead($task[10]) == $GUI_CHECKED Then For $i = $task[0]-1 To 1 Step -1 GUICtrlSetState($task[$i], $GUI_CHECKED) Next ElseIf GUICtrlRead($task[10]) == $GUI_UNCHECKED Then For $i = $task[0]-1 To 1 Step -1 GUICtrlSetState($task[$i], $GUI_UNCHECKED) Next EndIf EndSwitch WEnd EndFunc #EndRegion GUI code #Region INI READ/WRITE Func ini($iniFile, $section, $key, $value, $iniread = 1) ;Read or edit value in default.ini $iniOpen = FileOpen($iniFile, 2) c("read state = " & $iniread) Switch $iniread Case 0 ;0 = Write / Overwrite Return IniWrite($iniFile, $section, $key, $value) Case 1 ;1 = Read Return IniRead($iniFile, $section, $key, $value) Case 2 ;2 = Write Section Return IniWriteSection($iniFile, $section, $value) EndSwitch EndFunc ;==>ini Func _ImportIni() $iniFile = FileOpenDialog("Choose File...", $ConfigDir, "Config files (*.ini)", 1, "default.ini") For $i = 1 to $task[0]-1 Step 1 $in = _GetCtrlClass($task[$i]) Select Case $in="Checkbox" If GUICtrlRead($task[$i])==$GUI_CHECKED Then c("task(" & $i & ") = " & "1") ElseIf GUICtrlRead($task[$i])==$GUI_UNCHECKED then c("task(" & $i & ") = " & GUICtrlRead($task[$i],1)) EndIf Case $in="Input" c("task(" & $i & ") = " & GUICtrlRead($task[$i])) EndSelect Next EndFunc Func _ExportIni() $exportIni = FileSaveDialog("Select destination folder and desired File name...", @ScriptDir, "Configuration File (*.ini)", $FD_PROMPTOVERWRITE) If @error Then c("Dialog was cancelled.") Else FileOpen($exportIni, "") For $i = 1 to $task[0]-1 Step 1 $in = _GetCtrlClass($task[$i]) If $in = "checkbox" Then c("task " & $i & " = checkbox") Else c($i & " = " & "it's something else...") EndIf Next EndIf EndFunc Func c($cw) ConsoleWrite($cw & @CRLF) EndFunc Func _GetCtrlClass($hHandle) Local Const $GWL_STYLE = -16 Local $iLong, $sClass If IsHWnd($hHandle) = 0 Then $hHandle = GUICtrlGetHandle($hHandle) If IsHWnd($hHandle) = 0 Then Return SetError(1, 0, "Unknown") EndIf EndIf $sClass = _WinAPI_GetClassName($hHandle) If @error Then Return "Unknown" EndIf $iLong = _WinAPI_GetWindowLong($hHandle, $GWL_STYLE) If @error Then Return SetError(2, 0, 0) EndIf Switch $sClass Case "Button" Select Case BitAND($iLong, $BS_GROUPBOX) = $BS_GROUPBOX Return "Group" Case BitAND($iLong, $BS_CHECKBOX) = $BS_CHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Return "Checkbox" Case BitAND($iLong, $BS_RADIOBUTTON) = $BS_RADIOBUTTON Return "Radio" Case BitAND($iLong, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Return "Radio" EndSelect Case "Edit" Select Case BitAND($iLong, $ES_WANTRETURN) = $ES_WANTRETURN Return "Edit" Case Else Return "Input" EndSelect Case "Static" Select Case BitAND($iLong, $SS_BITMAP) = $SS_BITMAP Return "Pic" Case BitAND($iLong, $SS_ICON) = $SS_ICON Return "Icon" Case BitAND($iLong, $SS_LEFT) = $SS_LEFT If BitAND($iLong, $SS_NOTIFY) = $SS_NOTIFY Then Return "Label" EndIf Return "Graphic" EndSelect Case "ComboBox" Return "Combo" Case "ListBox" Return "List" Case "msctls_progress32" Return "Progress" Case "msctls_trackbar32" Return "Slider" Case "SysDateTimePick32" Return "Date" Case "SysListView32" Return "ListView" Case "SysMonthCal32" Return "MonthCal" Case "SysTabControl32" Return "Tab" Case "SysTreeView32" Return "TreeView" EndSwitch Return $sClass EndFunc #EndRegion Get type of control Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this: Spoiler #1. I am a native French speaker and learned English mainly from chatting with others players in online games. #2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor. ~WilliamasKumeliukas
abberration Posted July 20, 2021 Posted July 20, 2021 You did something great with your $task array. By putting it into an array, you cycle through a loop reading their values with GuiCtrlRead. I would suggest putting all your input boxes and checkboxes into the array. Maybe name them like hUserPrefs or something like that. You must read each input or choice and then write it to the INI file. Here's a super simple example. #include <Array.au3> Global $hItems[99] Global $GUI = GUICreate(@ScriptName, 1013, 620) $hItems[1] = GUICtrlCreateLabel("hi", 20, 20) $hItems[2] = GUICtrlCreateLabel("bye", 20, 40) $hItems[3] = GUICtrlCreateLabel("still here?", 20, 60) GUISetState(@SW_SHOW, $GUI) For $i = 1 To 3 $sCurrentRead = GUICtrlRead($hItems[$i]) IniWrite("MyIni.ini", "Read", "Value" & $i, $sCurrentRead) Next sleep (2000) The process is similar with importing. You also need to read all the INI items (preferably to an array) and then create your GUI items (also preferably with an array in case they want to export the updated fields). I hope this made sense. If not, we will try to help explain further. Easy MP3 | Software Installer | Password Manager
Solution Subz Posted July 21, 2021 Solution Posted July 21, 2021 Its difficult to understand the relationship between the checkbox list and group 1/group 2 lists. Personally I would used 3 2d arrays: $g_aTask[][3] $g_aTask[x][0] = "Task x" $g_aTask[x][1] = "Control Id" $g_aTask[x][2] = Height (This can be used later to add additional tasks) $g_aGroup1[][3] $g_aGroup1[x][0] = "Task Value" $g_aGroup1[x][1] = "Control Id" $g_aGroup1[x][2] = Height (This can be used later to add additional tasks) $g_aGroup1[x][3] = "Label Id" $g_aGroup2[][3] $g_aGroup2[x][0] = "Task Value" $g_aGroup2[x][1] = "Control Id" $g_aGroup2[x][2] = Height (This can be used later to add additional tasks) $g_aGroup2[x][3] = "Label Id" You can then loop through the array and populate the information from the 3 different arrays basic example (includes ini import/export functionality). Hopefully you can decipher how the code works and work it into your own. expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <Array.au3> #include <GuiButton.au3> #include <TreeViewConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", $GUI_DOCKAUTO) Global $g_sConfigDir = @ScriptDir Global $sIniFilePath = $g_sConfigDir & "\default.ini" Global $g_aCheckboxItems[][3] = [["Task Name", "Control Id", "Height"]], $g_iCheckboxItems = 12 Global $g_aGroup1Items[][4] = [["Group Task Name", "Control Id", "Height", "Label Id"]], $g_iGroup1Items = 7 Global $g_aGroup2Items[][4] = [["Group Task Name", "Control Id", "Height", "Label Id"]], $g_iGroup2Items = 5 GUI() Func GUI() Local $iMsg Local $GUI = GUICreate(@ScriptName, 1013, 620) Local $idTab1 = GUICtrlCreateTab(0, 0, 697, 541, -1, -1) GUICtrlSetState($idTab1, $GUI_ONTOP) GUICtrlCreateTabItem("Tab 1") GUICtrlSetResizing(-1, 70) Local $FileMenu = GUICtrlCreateMenu("FileMenu") Local $FileImp = GUICtrlCreateMenuItem("Import / Load", $FileMenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) Local $FileExp = GUICtrlCreateMenuItem("Export / Save",$FileMenu) GUICtrlCreateMenuItem("", $Filemenu, 2) ; create a separator line Local $FileEx = GUICtrlCreateMenuItem("Exit",$FileMenu) Local $HelpMenu = GUICtrlCreateMenu("HelpMenu") Local $HelpInfo = GUICtrlCreateMenuItem("HelpInfo",$HelpMenu) GUICtrlCreateGraphic(705, 45, 300, 455, BitOR($GUI_SS_DEFAULT_GRAPHIC, $SS_WHITEFRAME, $WS_BORDER)) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFFFFF) _GuiCtrlCreateCheckBoxes($g_aCheckboxItems, 50, $g_iCheckboxItems) GUICtrlSetData($g_aCheckboxItems[UBound($g_aCheckboxItems)-1][1], $g_aCheckboxItems[UBound($g_aCheckboxItems)-1][0] & " (Select All)") Local $hInput = GUICtrlCreateInput("hInput", 710, 440, 280, 30) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) GUICtrlSetState(-1, $GUI_DISABLE) Local $idResetTasks = GUICtrlCreateButton("Reset", 820, 510, 80, 30) Local $idRunTasks = GUICtrlCreateButton("Run", 910, 510, 80, 30) GUICtrlCreateLabel("label[1]:", 780, 23, 160, 18, $SS_CENTER, -1) GUICtrlSetFont(-1, 12, 800, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlCreateGroup("Group 1",6,35,380,230) _GuiCtrlCreateInputItems($g_aGroup1Items, 50, $g_iGroup1Items) GUICtrlCreateGroup("Group 2",6,275,380,230) _GuiCtrlCreateInputItems($g_aGroup2Items, 290, $g_iGroup2Items) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW, $GUI) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $FileEx Exit Case $FileImp _ImportIni() Case $FileExp _ExportIni() Case $idResetTasks _GuiCtrlCreateCheckBoxes($g_aCheckboxItems, 50, $g_iCheckboxItems) GUICtrlSetData($g_aCheckboxItems[UBound($g_aCheckboxItems)-1][1], $g_aCheckboxItems[UBound($g_aCheckboxItems)-1][0] & " (Select All)") _GuiCtrlCreateInputItems($g_aGroup1Items, 50, $g_iGroup1Items) _GuiCtrlCreateInputItems($g_aGroup2Items, 290, $g_iGroup2Items) Case $g_aCheckboxItems[UBound($g_aCheckboxItems) - 1][1] If GUICtrlRead($g_aCheckboxItems[UBound($g_aCheckboxItems) - 1][1]) == $GUI_CHECKED Then For $i = UBound($g_aCheckboxItems)-1 To 1 Step -1 GUICtrlSetState($g_aCheckboxItems[$i][1], $GUI_CHECKED) Next ElseIf GUICtrlRead($g_aCheckboxItems[UBound($g_aCheckboxItems) - 1][1]) == $GUI_UNCHECKED Then For $i = UBound($g_aCheckboxItems)-1 To 1 Step -1 GUICtrlSetState($g_aCheckboxItems[$i][1], $GUI_UNCHECKED) Next EndIf EndSwitch WEnd EndFunc Func _GuiCtrlCreateCheckBoxes(ByRef $_g_aCheckboxTasks, $_iTop = 50, $_iCheckboxItems = 10, $_aCheckboxTasks = Default) Local $sCheckboxTask = "", $idCheckboxTask For $i = UBound($g_aCheckboxItems) - 1 To 1 Step - 1 GUICtrlDelete($g_aCheckboxItems[$i][1]) _ArrayDelete($g_aCheckboxItems, $i) Next If IsArray($_aCheckboxTasks) Then For $i = 1 To UBound($_aCheckboxTasks) - 1 $sCheckboxTask = $_aCheckboxTasks[$i][0] $idCheckboxTask = GUICtrlCreateCheckbox($sCheckboxTask, 710, $_iTop, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetState($idCheckboxTask, Execute($_aCheckboxTasks[$i][1])) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) _ArrayAdd($_g_aCheckboxTasks, $sCheckboxTask & "|" & $idCheckboxTask & "|" & $_iTop) $_iTop += 25 Next Else For $i = 1 To $_iCheckboxItems $sCheckboxTask = "Task " & $i $idCheckboxTask = GUICtrlCreateCheckbox($sCheckboxTask, 710, $_iTop, 260, 20, BitOR($TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES)) GUICtrlSetFont(-1, 13, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) GUICtrlSetBkColor(-1, $COLOR_WHITE) _ArrayAdd($_g_aCheckboxTasks, $sCheckboxTask & "|" & $idCheckboxTask & "|" & $_iTop) $_iTop += 25 Next EndIf EndFunc Func _GuiCtrlCreateInputItems(ByRef $_g_aInputTasks, $_iTop, $_iGroupItems, $_aInputTasks = Default) Local $sInputTask = "", $idInputTask, $idLabelTask For $i = UBound($_g_aInputTasks) - 1 To 1 Step - 1 GUICtrlDelete($_g_aInputTasks[$i][1]) GUICtrlDelete($_g_aInputTasks[$i][3]) _ArrayDelete($_g_aInputTasks, $i) Next If IsArray($_aInputTasks) Then For $i = 1 To UBound($_aInputTasks) - 1 $idLabelTask = GUICtrlCreateLabel("Label " & $i & " : ", 77, $_iTop, 95, Default, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $sInputTask = $_aInputTasks[$i][1] $idInputTask = GUICtrlCreateInput($sInputTask, 125, $_iTop, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetState($idInputTask, Execute($_aInputTasks[$i][1])) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) _ArrayAdd($_g_aInputTasks, $sInputTask & "|" & $idInputTask & "|" & $_iTop & "|" & $idLabelTask) $_iTop += 30 Next Else For $i = 1 To $_iGroupItems $idLabelTask = GUICtrlCreateLabel("Label " & $i & " : ", 77, $_iTop, 95, Default, $SS_CENTERIMAGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $sInputTask = "Task[" & $i & "]" $idInputTask = GUICtrlCreateInput($sInputTask, 125, $_iTop, 222, 20, Default, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 10, 400, 0, "Lucida Bright", 5) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) _ArrayAdd($_g_aInputTasks, $sInputTask & "|" & $idInputTask & "|" & $_iTop & "|" & $idLabelTask) $_iTop += 30 Next EndIf EndFunc Func _ImportIni() Local $sIniFilePath = FileOpenDialog("Choose File...", $g_sConfigDir, "Config files (*.ini)", 1, "default.ini") If @error Then Return Local $aCheckboxItems = IniReadSection($sIniFilePath, "Checkbox Tasks") If Not @error Then _GuiCtrlCreateCheckBoxes($g_aCheckboxItems, 50, $g_iCheckboxItems, $aCheckboxItems) Local $aGroup1Items = IniReadSection($sIniFilePath, "Group1 Tasks") If Not @error Then _GuiCtrlCreateInputItems($g_aGroup1Items, 50, $g_iGroup1Items, $aGroup1Items) _ArrayDisplay($aGroup1Items) Local $aGroup2Items = IniReadSection($sIniFilePath, "Group2 Tasks") If Not @error Then _GuiCtrlCreateInputItems($g_aGroup2Items, 290, $g_iGroup2Items, $aGroup2Items) EndFunc Func _ExportIni() Local $sIniFilePath = FileSaveDialog("Select destination folder and desired File name...", @ScriptDir, "Configuration File (*.ini)", $FD_PROMPTOVERWRITE, "default.ini") If @error Then Return IniDelete($sIniFilePath, "Checkbox Tasks") For $i = 1 To UBound($g_aCheckboxItems) - 1 IniWrite($sIniFilePath, "Checkbox Tasks", $g_aCheckboxItems[$i][0], GUICtrlRead($g_aCheckboxItems[$i][1])) Next IniDelete($sIniFilePath, "Group1 Tasks") For $i = 1 To UBound($g_aGroup1Items) - 1 IniWrite($sIniFilePath, "Group1 Tasks", $g_aGroup1Items[$i][0], GUICtrlRead($g_aGroup1Items[$i][1])) Next IniDelete($sIniFilePath, "Group2 Tasks") For $i = 1 To UBound($g_aGroup2Items) - 1 IniWrite($sIniFilePath, "Group2 Tasks", $g_aGroup2Items[$i][0], GUICtrlRead($g_aGroup2Items[$i][1])) Next EndFunc
WilliamasKumeliukas Posted July 22, 2021 Author Posted July 22, 2021 7 hours ago, Subz said: Its difficult to understand the relationship between the checkbox list and group 1/group 2 lists. Personally I would used 3 2d arrays: $g_aTask[][3] $g_aTask[x][0] = "Task x" $g_aTask[x][1] = "Control Id" $g_aTask[x][2] = Height (This can be used later to add additional tasks) $g_aGroup1[][3] $g_aGroup1[x][0] = "Task Value" $g_aGroup1[x][1] = "Control Id" $g_aGroup1[x][2] = Height (This can be used later to add additional tasks) $g_aGroup1[x][3] = "Label Id" $g_aGroup2[][3] $g_aGroup2[x][0] = "Task Value" $g_aGroup2[x][1] = "Control Id" $g_aGroup2[x][2] = Height (This can be used later to add additional tasks) $g_aGroup2[x][3] = "Label Id" You can then loop through the array and populate the information from the 3 different arrays basic example (includes ini import/export functionality). Hopefully you can decipher how the code works and work it into your own. First of all, Thank you for your time, I really appreciate it, I like this approach and will try work it on my own Regards, ~WilliamasKumeliukas Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this: Spoiler #1. I am a native French speaker and learned English mainly from chatting with others players in online games. #2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor. ~WilliamasKumeliukas
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