*Known problem: It crashes when creating the treeview for a LARGE ini that consists of 2K sections. Help solving that would be great also.
Beta is needed.
#include <GUIConstants.au3> #Include <GuiTreeView.au3> #include <File.au3> $INIFile = 'C:\GUI Label Entry.ini' $EditMainGUI = GUICreate("View/Edit INI File", 350, 193) $treeview = GUICtrlCreateTreeView(6, 6, 230, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) _ReadinINI() $b_INIView = GUICtrlCreateButton("&View/Edit", 245, 6, 100, 20) $b_INIColExp = GUICtrlCreateButton("&Collapse./Expand.", 245, 30, 100, 20) $b_INIPrint = GUICtrlCreateButton("&Print INI File", 245, 54, 100, 20) $b_INIExit = GUICtrlCreateButton("&Exit", 245, 78, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $b_INIExit Or $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $b_INIView $item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item If $item = 0 Then _HideGUIMSGBoxShowGUI(64, "INI Edit", "No item currently selected.") Else $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item If ($advmsg[0] == 0) Then _HideGUIMSGBoxShowGUI(16, "INI Edit: Error", "Error while retrieving info about selected item.") Else Global $Value = IniRead($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], 'ERROR') GUISetState(@SW_HIDE) $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Current key selected: " & $advmsg[0] & @CR _ & ' With a value of: ' & $Value & @CR _ & @CR _ & 'Do you want to edit this value?') If $Edit = 6 Then; User wants to edit the value _EditValue() Else GUISetState(@SW_SHOW) EndIf EndIf EndIf Case $msg = $b_INIColExp $item = GUICtrlRead($treeview) If $item > 0 Then $hItem = GUICtrlGetHandle($item) GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem) EndIf Case $msg = $b_INIPrint _FilePrint ($INIFile) EndSelect WEnd GUIDelete() Exit Func _HideGUIMSGBoxShowGUI($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText) GUISetState(@SW_HIDE) Global $MsgAsr = MsgBox($MsgBoxOptions, $MsgBoxTitle, $MsgBoxText) GUISetState(@SW_SHOW) Return $MsgAsr EndFunc ;==>_HideGUIMSGBoxShowGUI Func _EditValue() $EditGUI = GUICreate("INI Edit", 392, 89, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUICtrlCreateLabel("Value:", 10, 10, 30, 20) $Input_EditValue = GUICtrlCreateInput($Value, 10, 30, 370, 20) $b_EditValue_Save = GUICtrlCreateButton("Save", 10, 60, 50, 20) $b_EditValue_Restore = GUICtrlCreateButton("Restore Original Value", 70, 60, 120, 20) $b_EditValue_Exit = GUICtrlCreateButton("Exit", 200, 60, 50, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $b_EditValue_Exit ExitLoop Case $msg = $b_EditValue_Restore GUICtrlSetData($Input_EditValue, $Value) GUICtrlSetState($Input_EditValue, $GUI_FOCUS) Case $msg = $b_EditValue_Save $Edit = MsgBox(48 + 4096 + 4, "INI Edit", "Are you sure you want to replace:" & @CR _ & ' ' & $Value & @CR _ & 'With:' & @CR _ & ' ' & GUICtrlRead($Input_EditValue)) If $Edit = 6 Then; User wants to edit the value $Err = IniWrite($INIFile, _GUICtrlTreeViewGetText($treeview, _GUICtrlTreeViewGetParentHandle($treeview)), $advmsg[0], GUICtrlRead($Input_EditValue)) If $Err = 0 Then MsgBox(4096, 'Error Occured', 'New value was NOT added to the INI File.') GUISwitch($EditMainGUI) _GUICtrlTreeViewExpand($treeview, 0) GUISwitch($EditGUI) ExitLoop EndIf EndSelect WEnd GUIDelete() GUISetState(@SW_SHOW) EndFunc ;==>_EditValue Func _ReadinINI() $var = IniReadSectionNames($INIFile) If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else Dim $generalitem[1] For $i = 1 To $var[0] ReDim $generalitem[UBound($generalitem) + 1] $generalitem [UBound($generalitem) - 1] = GUICtrlCreateTreeViewItem($var[$i], $treeview) GUICtrlSetState(-1, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) GUICtrlSetColor(-1, 0x0000C0) $var1 = IniReadSection($INIFile, $var[$i]) If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Exit Else For $ii = 1 To $var1[0][0] $DetailItem = GUICtrlCreateTreeViewItem($var1[$ii][0], $generalitem[$i]) Next EndIf Next EndIf EndFunc ;==>_ReadinINI
Edited by strate, 06 May 2006 - 11:23 PM.





