Jump to content

GUI that constantly read/write an ini file


sensalim
 Share

Recommended Posts

Sensalim, do you know how to read/write an INI file?

My code would do it in somewhat the following order:

  • Create GUI
  • Read INI file
  • Set GUI control states
  • Enter GUIMessage loop
  • On message, write to ini file
  • Close
Have a look at IniRead/IniWrite, GUI Messages, GUI Control States

I think that should help push you in the right direction. Best of luck ;)

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:

%programfiles%/AutoIt3/autoit3.chm
Link to comment
Share on other sites

Here is an example script.

#include <GUIConstantsEx.au3>
If Not FileExists(@ScriptDir&"Settings.ini") Then
    FileWrite(@ScriptDir&"Settings.ini", "[Settings]"&@CRLF&"Checkbox1=0"&@CRLF&"Checkbox2=1")
EndIf
$Gui = GUICreate("INI Checkbox Example", 200, 200)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox 1", 50, 50)
$Checkbox1Setting = IniRead(@ScriptDir&"Settings.ini", "Settings", "Checkbox1", 0)
If $Checkbox1Setting = 1 Then
    GUICtrlSetState($Checkbox1, $GUI_CHECKED)
EndIf
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox 2", 50, 100)
$Checkbox2Setting = IniRead(@ScriptDir&"Settings.ini", "Settings", "Checkbox2", 0)
If $Checkbox2Setting = 1 Then
    GUICtrlSetState($Checkbox2, $GUI_CHECKED)
EndIf
GUISetState(@SW_SHOW, $Gui)
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                IniWrite(@ScriptDir&"Settings.ini", "Settings", "Checkbox1", 1)
            Else
                IniWrite(@ScriptDir&"Settings.ini", "Settings", "Checkbox1", 0)
            EndIf
        Case $Checkbox2
            If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
                IniWrite(@ScriptDir&"Settings.ini", "Settings", "Checkbox2", 1)
            Else
                IniWrite(@ScriptDir&"Settings.ini", "Settings", "Checkbox2", 0)
            EndIf
    EndSwitch
WEnd

Now please read the help file because this is pretty basic stuff.

Link to comment
Share on other sites

Ok I didn't explain this right.

The GUI needs to handle any changes made to the ini file whether by itself or by someone else editing the ini or by some other program making modification to that ini file.

Sorry for any trouble.

Edit:

I changed it to onevent mode and put "read ini" function in the while loop and it seems to work.

Is this not the right way or inefficient way?

Edited by sensalim
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...