Config bearbeiten und Config bearbeiten

  • Hey leute,

    ich will in meinem kleinem Programm eine Config bearbeitung einbauen
    Ich habe momentan eine Config in der man einen Namen und eine URL eintragen kann.
    Dies möchte ich jetzt aber über das Programm selber machen

    So wollte ich die Bearbeitung der Config machen.

    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Form1", 413, 352, 216, 256)
    $Button1 = GUICtrlCreateButton("Hinzufügen", 296, 32, 107, 25)
    $Button2 = GUICtrlCreateButton("Alle Löschen", 296, 64, 107, 25)
    $Button3 = GUICtrlCreateButton("Makierung Löschen", 296, 96, 107, 25)
    $Button4 = GUICtrlCreateButton("Fertig", 296, 128, 105, 25)
    $Input1 = GUICtrlCreateInput("Input1", 56, 296, 281, 21)
    $Label1 = GUICtrlCreateLabel("Name.:", 8, 296, 38, 17)
    $Label2 = GUICtrlCreateLabel("URL.:", 8, 328, 32, 17)
    $Input2 = GUICtrlCreateInput("Input2", 56, 328, 281, 21)
    $List1 = GUICtrlCreateList("", 8, 8, 281, 279)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit][autoit][/autoit][autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit][autoit][/autoit][autoit]

    EndSwitch
    WEnd

    [/autoit]

    Wie kann ich jetzt die Config mit diesem Scirpt ansteuern und bearbeiten?
    und meine Config bearbeitung auch in meinem Programm einbinden?

  • Wenn du mit config eine ini-Datei meinst (verstehe ich so) dann:

    [autoit]

    IniWrite

    [/autoit]

    o
    L_/
    | ||

    This ist janaiky. Copy janaiky into your signature to help him on the war to the Weltherrschaft.

  • Erzähl doch mal genauer was du willst. Übrigens heißt es Markierung und nicht Makierung und Name ist keine Abkürzung also Punkt weg, genauso auch bei URL, oder du schreibst U.R.L.;).

  • Hab hier was "cooles" um eine ini im Listview darzustellen, die Items können mit dem entsprechenden Style auch onthefly editiert werden.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    global $ini = @ScriptDir & "\dvb-tools.ini" ;Pfad zur ini

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Ini read to Listview - Beispiel", 700, 500, -1, -1)
    $ListView1 = GUICtrlCreateListView("", 20, 20,660 , 350)
    $hlistview= GUICtrlGetHandle($ListView1)
    _GUICtrlListView_AddColumn($hListView, "Key", 200)
    _GUICtrlListView_AddColumn($hListView, "Value", 450)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Button2 = GUICtrlCreateButton("Iniread", 20, 420, 120, 33, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button2
    _Initolistview($hlistview, $ini)
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Initolistview($hwnd, $path)
    ; nuts (http://www.autoit.de)
    ; $hwnd = Handle to the listview
    ; $path = ini path
    local $anames, $aread
    If not IsHWnd($hwnd) then
    SetError(1) ;not a handle -> @error = 1
    Return
    ElseIf not FileExists($path) then
    SetError(2) ;ini not found -> @error = 2
    Return
    endif
    $anames = IniReadSectionNames($path)
    $counter = -1;_GUICtrlListView_GetItemCount($hwnd)
    for $i = 1 to $anames[0]
    $aread = IniReadSection($path, $anames[$i])
    if @error then
    $counter+= 1
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    _GUICtrlListView_AddItem($hwnd, "Kein Eintrag")
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    ContinueLoop
    endif
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    for $x = 1 to $aread[0][0]
    $counter+= 1
    _GUICtrlListView_AddItem($hwnd, $aread[$x][0])
    _GUICtrlListView_AddSubItem($hwnd,$counter, $aread[$x][1],1)
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    next

    [/autoit] [autoit][/autoit] [autoit]

    next
    endfunc

    [/autoit]
  • Kann man es nicht einfach so machen das man auf Hinzufügen klicken kann und dann öffnet sich ein kleine PopUp feld wo man einfach den Namen und die URL Eintragen kann oder der Name Automatisch bezogen wird...

  • Bsp:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $ini = @ScriptDir & "\dvb-tools.ini" ;Pfad zur ini

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Ini read to Listview - Beispiel", 700, 500, -1, -1)
    $ListView1 = GUICtrlCreateListView("", 20, 20, 660, 350)
    $hlistview = GUICtrlGetHandle($ListView1)
    _GUICtrlListView_AddColumn($hlistview, "Key", 200)
    _GUICtrlListView_AddColumn($hlistview, "Value", 450)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Button2 = GUICtrlCreateButton("Iniread", 20, 420, 120, 33, 0)
    $Button1 = GUICtrlCreateButton("Add", 220, 420, 120, 33, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    _Initolistview($hlistview, $ini)
    Case $Button1
    _Add()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Initolistview($hwnd, $path)
    ; nuts (http://www.autoit.de)
    ; $hwnd = Handle to the listview
    ; $path = ini path
    Local $anames, $aread
    If Not IsHWnd($hwnd) Then
    SetError(1) ;not a handle -> @error = 1
    Return
    ElseIf Not FileExists($path) Then
    SetError(2) ;ini not found -> @error = 2
    Return
    EndIf
    $anames = IniReadSectionNames($path)
    $counter = -1;_GUICtrlListView_GetItemCount($hwnd)
    For $i = 1 To $anames[0]
    $aread = IniReadSection($path, $anames[$i])
    If @error Then
    $counter += 1
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    _GUICtrlListView_AddItem($hwnd, "Kein Eintrag")
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    ContinueLoop
    EndIf
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    For $x = 1 To $aread[0][0]
    $counter += 1
    _GUICtrlListView_AddItem($hwnd, $aread[$x][0])
    _GUICtrlListView_AddSubItem($hwnd, $counter, $aread[$x][1], 1)
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Next
    EndFunc ;==>_Initolistview

    [/autoit] [autoit][/autoit] [autoit]

    Func _Add()
    #region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Form1", 431, 200, 192, 124)
    $Input1 = GUICtrlCreateInput("", 40, 64, 113, 21)
    $Input2 = GUICtrlCreateInput("", 192, 64, 177, 21)
    $Label1 = GUICtrlCreateLabel("Key", 40, 32, 36, 17)
    $Label2 = GUICtrlCreateLabel("Value", 192, 32, 36, 17)
    $Button = GUICtrlCreateButton("Übernehmen", 140, 150, 120, 33, 0)
    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_SHOW, $Form2)
    #endregion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    case $Button
    local $count
    _GUICtrlListView_AddItem($hlistview,GUICtrlRead($Input1))
    local $count=_GUICtrlListView_GetItemCount($hlistview)-1
    _GUICtrlListView_AddSubItem($hlistview,$count,GUICtrlRead($Input1),1)
    _GUICtrlListView_SetItemGroupID($hlistview,$count,1)
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    EndSwitch
    WEnd
    EndFunc ;==>_Add

    [/autoit]


    Zu welcher Gruppe das neue Item hinzugefügt werden soll kann man auch Abfragen und z.B. per Combobox einstellen (fehlt mir jetzt die Zeit für ein Beispiel).

    Alternativ: Man liest den Wert der Inputs (oder wo sonst die Infos für den neuen Eintrag stehen) aus, speichert diese in die .ini (Iniwrite) und läd die ini erneut ins Listview. Ist vielleicht einfacher, meiner Meinung nach aber keine saubere Lösung.

  • so müsse es gehen (bei mir jedenfalls):

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $ini = @ScriptDir & "\dvb-tools.ini" ;Pfad zur ini

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Ini read to Listview - Beispiel", 700, 500, -1, -1)
    $ListView1 = GUICtrlCreateListView("", 20, 20, 660, 350)
    $hlistview = GUICtrlGetHandle($ListView1)
    _GUICtrlListView_AddColumn($hlistview, "Key", 200)
    _GUICtrlListView_AddColumn($hlistview, "Value", 450)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Button2 = GUICtrlCreateButton("Iniread", 20, 420, 120, 33, 0)
    $Button1 = GUICtrlCreateButton("Add", 220, 420, 120, 33, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    _Initolistview($hlistview, $ini)
    Case $Button1
    _Add()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Initolistview($hwnd, $path)
    ; nuts (http://www.autoit.de)
    ; $hwnd = Handle to the listview
    ; $path = ini path
    Local $anames, $aread
    If Not IsHWnd($hwnd) Then
    SetError(1) ;not a handle -> @error = 1
    Return
    ElseIf Not FileExists($path) Then
    SetError(2) ;ini not found -> @error = 2
    Return
    EndIf
    $anames = IniReadSectionNames($path)
    $counter = -1;_GUICtrlListView_GetItemCount($hwnd)
    For $i = 1 To $anames[0]
    $aread = IniReadSection($path, $anames[$i])
    If @error Then
    $counter += 1
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    _GUICtrlListView_AddItem($hwnd, "Kein Eintrag")
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    ContinueLoop
    EndIf
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    For $x = 1 To $aread[0][0]
    $counter += 1
    _GUICtrlListView_AddItem($hwnd, $aread[$x][0])
    _GUICtrlListView_AddSubItem($hwnd, $counter, $aread[$x][1], 1)
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Next
    EndFunc ;==>_Initolistview

    [/autoit] [autoit][/autoit] [autoit]

    Func _Add()
    #region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Form1", 431, 200, 192, 124)
    $Input1 = GUICtrlCreateInput("", 40, 64, 113, 21)
    $Input2 = GUICtrlCreateInput("", 192, 64, 177, 21)
    $Label1 = GUICtrlCreateLabel("Key", 40, 32, 36, 17)
    $Label2 = GUICtrlCreateLabel("Value", 192, 32, 36, 17)
    $Button = GUICtrlCreateButton("Übernehmen", 140, 150, 120, 33, 0)
    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_SHOW, $Form2)
    #endregion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    case $Button
    local $count
    _GUICtrlListView_AddItem($hlistview,GUICtrlRead($Input1))
    local $count=_GUICtrlListView_GetItemCount($hlistview)-1
    _GUICtrlListView_AddSubItem($hlistview,$count,GUICtrlRead($Input1),1)
    _GUICtrlListView_SetItemGroupID($hlistview,$count,1)
    IniWrite($ini, _GUICtrlListView_GetItemGroupID($hlistview, $count), GuiCtrlRead($Input1), GuiCtrlRead($Input2))
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    EndSwitch
    WEnd
    EndFunc ;==>_Add

    [/autoit]

    da muss aber noch ein fehler drinnen sein:
    irgendwie liest er er die ini noch dem aktuallisieren falsch ein wenn man iniread macht. nur nach neustart des scripts geht es wieder

    o
    L_/
    | ||

    This ist janaiky. Copy janaiky into your signature to help him on the war to the Weltherrschaft.

  • Hab´s ein bisschen nachgebessert, sollte nun einwandfrei funktionieren....

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>
    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $ini = @ScriptDir & "\dvb-tools.ini" ;Pfad zur ini

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Ini read to Listview - Beispiel", 700, 500, -1, -1)
    $ListView1 = GUICtrlCreateListView("Key|Value", 20, 20, 660, 350)
    $hlistview = GUICtrlGetHandle($ListView1)
    _GUICtrlListView_SetColumnWidth($hlistview,0,100) ; Spaltenbreite feststzen...
    _GUICtrlListView_SetColumnWidth($hlistview,1,200) ; Spaltenbreite festsetzen SubItem...

    [/autoit] [autoit][/autoit] [autoit]

    $Button2 = GUICtrlCreateButton("Iniread", 20, 420, 120, 33, 0)
    $Button1 = GUICtrlCreateButton("Add", 220, 420, 120, 33, 0)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    _Initolistview($hlistview, $ini)
    Case $Button1
    _Add()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Initolistview($hwnd, $path)
    ; nuts (http://www.autoit.de)
    ; $hwnd = Handle to the listview
    ; $path = ini path
    Local $anames, $aread
    If Not IsHWnd($hwnd) Then
    SetError(1) ;not a handle -> @error = 1
    Return
    ElseIf Not FileExists($path) Then
    SetError(2) ;ini not found -> @error = 2
    Return
    EndIf
    $anames = IniReadSectionNames($path)
    $counter = -1;_GUICtrlListView_GetItemCount($hwnd)
    For $i = 1 To $anames[0]
    $aread = IniReadSection($path, $anames[$i])
    If @error Then
    $counter += 1
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    _GUICtrlListView_AddItem($hwnd, "Kein Eintrag")
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    ContinueLoop
    EndIf
    _GUICtrlListView_EnableGroupView($hwnd)
    _GUICtrlListView_InsertGroup($hwnd, -1, $i, $anames[$i])
    For $x = 1 To $aread[0][0]
    $counter += 1
    _GUICtrlListView_AddItem($hwnd, $aread[$x][0])
    _GUICtrlListView_AddSubItem($hwnd, $counter, $aread[$x][1], 1)
    _GUICtrlListView_SetItemGroupID($hwnd, $counter, $i)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Next
    EndFunc ;==>_Initolistview

    [/autoit] [autoit][/autoit] [autoit]

    Func _Add()
    #region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("Form1", 431, 200, 192, 124)
    $Input1 = GUICtrlCreateInput("", 40, 64, 113, 21)
    $Input2 = GUICtrlCreateInput("", 192, 64, 177, 21)
    $Label1 = GUICtrlCreateLabel("Key", 40, 32, 36, 17)
    $Label2 = GUICtrlCreateLabel("Value", 192, 32, 36, 17)
    $Button = GUICtrlCreateButton("Übernehmen", 140, 150, 120, 33, 0)
    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_SHOW, $Form2)
    #endregion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    case $Button
    local $count
    _GUICtrlListView_AddItem($hlistview,GUICtrlRead($Input1))
    local $count=_GUICtrlListView_GetItemCount($hlistview)-1
    _GUICtrlListView_AddSubItem($hlistview,$count,GUICtrlRead($Input2),1);hier war auch ein Fehler versteckt anstatt $Input2 war $Input1 angegeben...
    _GUICtrlListView_SetItemGroupID($hlistview,$count,1)
    IniWrite($ini, _GUICtrlListView_GetItemGroupID($hlistview, $count), GuiCtrlRead($Input1), GuiCtrlRead($Input2))
    GUIDelete($Form2)
    GUISetState(@SW_SHOW, $Form1)
    ExitLoop
    EndSwitch
    WEnd
    EndFunc ;==>_Add

    [/autoit] [autoit][/autoit] [autoit]

    ; Mfg Stinger....

    [/autoit]

    Mfg Stinger

    Spoiler anzeigen
    Zitat

    Ich weiß wo dein Haus wohnt... 8o

    2 Mal editiert, zuletzt von stinger2k (20. April 2010 um 22:06)