Jump to content

Best Way to Save GUI Control Settings


Recommended Posts

I have create a program that has become ever expanding. Previously I was just writing the GUI control values to a config file and the restoring them when the program starts again. This method has become tedious because of the number of controls I have. Does anyone know of a way to easily grab the values of ALL the GUI controls for saving and loading? Would using a database be easier than a config file. I am looking at around 60 controls that looks to grow up to 100 with time.

Thanks!

Link to comment
Share on other sites

  • Moderators

grasshopper3,

My 2p worth.

If you put the ControlIDs of the controls into an array as they were created, then you could save and load them very quickly with a small function which looped through them and called GUICtrlRead or GUICtrlSetData as required. ;)

Personally, I would say that 100 control/value pairs is hardly worth the effort of a database and would be fine in an ini file. :)

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

  • Moderators

grasshopper3,

You could do it like this: ;)

#include <GUIConstantsEx.au3>

Global $aControlID[4] ; Set this to match the number of controls

Global $sIniFile = @ScriptDir & "\Test.ini"

$hGUI = GUICreate("Test", 500, 500)

; Create the control
$hInput_A = GUICtrlCreateInput("", 10,  10, 200, 20)
; And save the ControlID in the Array
$aControlID[0] = $hInput_A
$hInput_B = GUICtrlCreateInput("", 10,  50, 200, 20)
$aControlID[1] = $hInput_B
$hInput_C = GUICtrlCreateInput("", 10,  90, 200, 20)
$aControlID[2] = $hInput_C
$hInput_D = GUICtrlCreateInput("", 10, 130, 200, 20)
$aControlID[3] = $hInput_D

; Loop through the array to set the saved values
For $i = 0 To 3
    GUICtrlSetData($aControlID[$i], IniRead($sIniFile, "Data", $i, "Not found"))
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Loop through the array to save the current values
            For $i = 0 To 3
                IniWrite($sIniFile, "Data", $i, GUICtrlRead($aControlID[$i]))
            Next
            Exit
    EndSwitch
WEnd

You coudl also put the ControlIDs directly into the array as the controls are created, but then you would have to remember which array element was which control. I think the code above is the best compromise - you get nice easy to use variables in your script and an array to loop through when needed. :idiot:

All clear? :)

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

  • Moderators

grasshopper3,

I like your listview UDF

Thanks. :)

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

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