Jump to content
Sign in to follow this  
Pedi7o

Create GUI from ini file data

Recommended Posts

Pedi7o

I have this ini file which contains 5 different variables. So i want some help to get the data from the ini file and then create a gui, create 1 checkbox for every "Name" key.

Then, if a checkbox is checked, write a registry key for every "key" key + "value" key + "path" key + "reg" key.

Settings.ini

[1]
Name = a
Key = key1
Value1 = 100
Value2 = 200
Value3 = 300
Path1 = patha
Path2 = pathb
Path3 = pathc
Reg1 = rega
Reg2 = regb
Reg3 = regc

[2]
Name = b
Key = key2
Value1 = 100
Value2 = 200
Value3 = 300
Path1 = patha
Path2 = pathb
Path3 = pathc
Reg1 = rega
Reg2 = regb
Reg3 = regc

[3]
Name = c
Key = key3
Value1 = 100
Value2 = 200
Value3 = 300
Path1 = patha
Path2 = pathb
Path3 = pathc
Reg1 = rega
Reg2 = regb
Reg3 = regc

Thanks in advance.

Edited by Pedi7o

Share this post


Link to post
Share on other sites
Melba23

Pedi7o,

That seems quite a reasonable task to code with AutoIt. What have you done so far which does not work? :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Pedi7o

Hello, so far I have this but is not exactly as practical as I want.

#include <GUIConstantsEx.au3>

Opt ("TrayIconDebug", 1)

;#NoTrayIcon

Global $Var[1]
$KeyMain = "HKEY_LOCAL_MACHINE\SoFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx"

$IniFile = @ScriptDir & "\Setting.ini"

GUICreate ("Instalando programas")

$Check_1 = GUICtrlCreateCheckbox (IniRead ($IniFile, "1", "Name", "Empty"), 10, 10, 120, 20)
$Check_2 = GUICtrlCreateCheckbox (IniRead ($IniFile, "2", "Name", "Empty"), 10, 30, 120, 20)
$Check_3 = GUICtrlCreateCheckbox (IniRead ($IniFile, "3", "Name", "Empty"), 10, 50, 120, 20)


$Save = GUICtrlCreateButton ("Save", 150, 250, 60, 30)
$Exit = GUICtrlCreateButton ("Exit", 220, 250, 60, 30)


GUISetState()

While 1

    $iMsg =  GUIGetMsg()

    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            Exit

        Case $iMsg = $Check_1
            If GUICtrlRead ($Check_1) = $GUI_CHECKED Then
                MsgBox (0, "", "CHECKED")
                RegWrite ($KeyMain & "\" & IniRead ($IniFile, "1", "Key1", "Empty"), "", "REG_SZ", IniRead ($IniFile, "1", "Name", "Empty"))
                RegWrite ($KeyMain & "\" & IniRead ($IniFile, "1", "Key1", "Empty"), "100", "REG_SZ", IniRead ($IniFile, "1", "Path1", "Empty"))
                RegWrite ($KeyMain & "\" & IniRead ($IniFile, "1", "Key1", "Empty"), "200", "REG_SZ", IniRead ($IniFile, "1", "Path2", "Empty"))
                RegWrite ($KeyMain & "\" & IniRead ($IniFile, "1", "Key1", "Empty"), "300", "REG_SZ", IniRead ($IniFile, "1", "Path3", "Empty"))
                RegWrite ($KeyMain & "\" & IniRead ($IniFile, "1", "Key1", "Empty"), "400", "REG_SZ", IniRead ($IniFile, "1", "Path4", "Empty"))
            EndIf


        Case $iMsg = $Save
            MsgBox (64, "", "Save!")

        Case $iMsg = $Exit
            Exit
    EndSelect

WEnd
Edited by Pedi7o

Share this post


Link to post
Share on other sites
Melba23

Pedi7o,

Does this look more "practical": :mellow:

#include <GUIConstantsEx.au3>

$IniFile = @ScriptDir & "\Setting.ini"

GUICreate ("Instalando programas")

$Check_1 = GUICtrlCreateCheckbox (IniRead ($IniFile, "1", "Name", "Empty"), 10, 10, 120, 20)
$Check_2 = GUICtrlCreateCheckbox (IniRead ($IniFile, "2", "Name", "Empty"), 10, 30, 120, 20)
$Check_3 = GUICtrlCreateCheckbox (IniRead ($IniFile, "3", "Name", "Empty"), 10, 50, 120, 20)

$Save = GUICtrlCreateButton ("Save", 150, 250, 60, 30)
$Exit = GUICtrlCreateButton ("Exit", 220, 250, 60, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Exit
            Exit
        Case $Save
            If GUICtrlRead ($Check_1) = $GUI_CHECKED Then
                MsgBox (0, "", "1 CHECKED")
                Write_Reg(1)
            EndIf
            If GUICtrlRead ($Check_2) = $GUI_CHECKED Then
                MsgBox (0, "", "2 CHECKED")
                Write_Reg(2)
            EndIf
            If GUICtrlRead ($Check_3) = $GUI_CHECKED Then
                MsgBox (0, "", "3 CHECKED")
                Write_Reg(3)
            EndIf
        Case $Save
            MsgBox (64, "", "Save!")
    EndSwitch

WEnd

Func Write_Reg($iIndex)
    RegWrite ($KeyMain & "\" & IniRead ($IniFile, $iIndex, "Key" & $iIndex, "Empty"), "", "REG_SZ", IniRead ($IniFile, $iIndex, "Name", "Empty"))
    For $i = 1 To 3
        RegWrite ($KeyMain & "\" & IniRead ($IniFile, $iIndex, "Key" & $i, "Empty"), 100 * $i, "REG_SZ", IniRead ($IniFile, $iIndex, "Path" & $i, "Empty"))
    Next
EndFunc

Not tested because I do not like filling up my registry with garbage. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Pedi7o

Lol, sure. Thanks you, Melba23

Btw, That's what virtual machines are for.

I'll check and test.

I wonder if there a way to get all the key values from the ini, create a checkbox and write its respective registry key.

I mean something like this:

; Create CheckBoxes
For $i = 1 To $aChecks[0][0]
    $aChecks[$i][0] = GUICtrlCreateCheckbox($aChecks[$i][1], 10, ($i * 30) + 20, 100, 20)
Next

Share this post


Link to post
Share on other sites
Pedi7o

Update:

Im editing the ini file and the code. And is working so far.

Edited by Pedi7o

Share this post


Link to post
Share on other sites
Syed23

Melba23,

I have just used your code and modified something to my knowledge. Please correct me if i am wrong!

#include <GUIConstantsEx.au3>

$file = IniReadSectionNames(@ScriptDir & "\Settings.ini")

GUICreate ("Instalando programas")

If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    $count = 10
    For $i = 1 To $file[0]
         GUICtrlCreateCheckbox(IniRead ($file, "1", "Name", "Empty"), 10, $count, 120, 20)
        $count = $count + 20
    Next
EndIf


$Save = GUICtrlCreateButton ("Save", 150, 250, 60, 30)
$Exit = GUICtrlCreateButton ("Exit", 220, 250, 60, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Exit
            Exit
        Case $Save
            If GUICtrlRead ($Check_1) = $GUI_CHECKED Then
                MsgBox (0, "", "1 CHECKED")
                Write_Reg(1)
            EndIf
            If GUICtrlRead ($Check_2) = $GUI_CHECKED Then
                MsgBox (0, "", "2 CHECKED")
                Write_Reg(2)
            EndIf
            If GUICtrlRead ($Check_3) = $GUI_CHECKED Then
                MsgBox (0, "", "3 CHECKED")
                Write_Reg(3)
            EndIf
        Case $Save
            MsgBox (64, "", "Save!")
    EndSwitch

WEnd

Func Write_Reg($iIndex)
    RegWrite ($KeyMain & "\" & IniRead ($IniFile, $iIndex, "Key" & $iIndex, "Empty"), "", "REG_SZ", IniRead ($IniFile, $iIndex, "Name", "Empty"))
    For $i = 1 To 3
        RegWrite ($KeyMain & "\" & IniRead ($IniFile, $iIndex, "Key" & $i, "Empty"), 100 * $i, "REG_SZ", IniRead ($IniFile, $iIndex, "Path" & $i, "Empty"))
    Next
EndFunc

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
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
Sign in to follow this  

×