Jump to content

can someone post an example of editing an ini file with a gui?


Recommended Posts

like make a simple gui with 1 label and 1 input box and then have it save an ini when the okay button is pressed?.

then i can try to build from there?

i know u can build the gui with koda.

its the actually making it do something that confuses me.

Link to comment
Share on other sites

Well take a look in the helpfile. If you search, and try it really isn't that hard :D

thanks for the simple example i asked for so i can try to learn instead of sending me to the help file which ive already read over and over and cant comprehend.

i asked for a simple gui with 1 input box and 1 button and 1 label that when the button is hit updates an ini file.

it might not be hard for someone thats actually been actively doing stuff with autoit but i havent and now i am trying to learn.

im not asking for anything that should be hard for an expert.

i need a gui with 25+ input boxes so its not like im gonna take this code and run either.

Edited by supadodger
Link to comment
Share on other sites

Its time to do it step by step, since you can comprehend one of the best help files ever, like dude! It has examples already! Every single AutoIt function has one, and if it doesn't, you'd have to have no brain to know what to do with it. Netherless, here is the explanation, which I am very sure you could have worked out, if you actually tried.

Please note, this information is charged at $US1,000,000/microsecond. Payment is required to be made into my newly created Swiss bank account....

So lets start with creating your GUI.

I assume you are using the full version of SciTE, so why don't you open than, then go Tool -> KODA, which is what we will use to create the GUI.

Posted Image

Now we will create the controls.

Now we go tools -> Generating form options -> And check the check box that says "generate events for all controls".

Posted Image

Now we close that dialogue, and go Tools -> Generate form code. If you wish to edit your GUI later, make sure you save it before you do this step. Click insert into SciTE.

Posted Image

And now we have our GUI.

Now we delete the crap we don't need from the message loop.

This stuff:

Case $Form1
        Case $Form1
        Case $Form1
        Case $Form1

Which leaves us with $GUI_EVENT_CLOSE, $input1 and $button1.

Now if we wanted to show text of the input when we press the button, we can do something like so:

Case $button1
            MsgBox (0, "I'm a noob and I can't read the helpfile!", GUICtrlRead ($Input1))

Fin.

EDIT:

Since you probably can't even do it with pictures, here's the final code:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
$Input1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21)
$button1 = GUICtrlCreateButton ("Button Text", 8, 40, 100, 29)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
        Case $button1
            MsgBox (0, "I'm a noob and I can't read the helpfile!", GUICtrlRead ($Input1))
    EndSwitch
WEnd
Edited by BrettF
Link to comment
Share on other sites

Now we delete the crap we don't need from the message loop.

This stuff:

Case $Form1

Case $Form1

Case $Form1

Case $Form1

i wont need that later?

that was a good explenation other than the hostility.

thanks for helping though.

each item on the gui has a Case

under that case is what is performed if u click that item right?

Link to comment
Share on other sites

OR!!! you can do what i and a few others like to do... write up the code manually THOUGH it is harder and usually you get somethings wrong (lots of guess and check) but its rewarding (ithink) writeing it up maually takes alittle more experience though... KODA will do your Fine untill then :D

Link to comment
Share on other sites

i wont need that later?

that was a good explenation other than the hostility.

thanks for helping though.

each item on the gui has a Case

under that case is what is performed if u click that item right?

No you will not need it, that is what I said right? I'm not sure why KODA does it, just anything with like that is useless for general purposes...
Link to comment
Share on other sites

Hmmm I went to the help file and copied the sample code for guictrlcreateinput

I quoted out lines 12 and 13

I replaced line 23 (Which was exitloop) with the sample code for iniwrite

I replaced the "this is a new value" with guictrlread($file)

All from the help file 4 steps

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $file, $btn, $msg
    
    GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
    $file = GUICtrlCreateInput("", 10, 5, 300, 20)
;~   GUICtrlSetState(-1, $GUI_DROPACCEPTED)
;~   GUICtrlCreateInput("", 10, 35, 300, 20)    
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)

    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                IniWrite("C:\Temp\myfile.ini", "section2", "key", GUICtrlRead($file))
        EndSelect
    WEnd

    MsgBox(4096, "drag drop file", GUICtrlRead($file))
EndFunc  ;==>Example

Giggity

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