Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
Global $iniFile = "Contact.ini"
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Carnet d'adresse Clients", 309, 154, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 16, 14, 217, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Input1 = GUICtrlCreateInput("", 104, 46, 127, 21)
$Input2 = GUICtrlCreateInput("", 104, 78, 200, 21)
$Input3 = GUICtrlCreateInput("", 104, 108, 200, 42)
$Label1 = GUICtrlCreateLabel("telephone", 34, 48, 51, 17)
$Label2 = GUICtrlCreateLabel("adresse postale", 28, 82, 62, 17)
$Label3 = GUICtrlCreateLabel("Information", 12, 110, 78, 17)
$Button1 = GUICtrlCreateButton("+", 250, 16, 25, 21)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("-", 275, 16, 25, 21)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $aData = IniReadSectionNames($iniFile)
If IsArray($aData) Then
For $i = 1 To $aData[0]
_GUICtrlComboBox_AddString($Combo1, $aData[$i])
Next
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo1
_Contact_Select(GUICtrlRead($Combo1))
Case $Button1
_Contact_Add()
Case $Button2
; supprime toute trace du contact selectionner dans la combobox dans le fichier .ini
If MsgBox(4 + 48 + 256, "Suppression", "Confirmer la suppression du contact") = 6 Then
_Contact_Delete()
EndIf
EndSwitch
WEnd
Func _Contact_Delete()
IniDelete($iniFile, GUICtrlRead($Combo1))
Local $iIndex = _GUICtrlComboBox_GetCurSel($Combo1)
_GUICtrlComboBox_DeleteString($Combo1, $iIndex)
_GUICtrlComboBox_SetCurSel($Combo1)
_Contact_Select("")
EndFunc
Func _Contact_Select($Name)
GUICtrlSetData($Input1, IniRead($iniFile, $Name, "telephone", ""))
GUICtrlSetData($Input2, IniRead($iniFile, $Name, "adresse_postale", ""))
GUICtrlSetData($Input3, IniRead($iniFile, $Name, "Information", ""))
EndFunc
Func _Contact_Add()
$Form2 = GUICreate("Carnet d'adresse Clients", 309, 154, 192, 124)
$Inputsave1 = GUICtrlCreateInput("", 98, 26, 137, 21)
$Inputsave2 = GUICtrlCreateInput("", 98, 52, 135, 21)
$Inputsave3 = GUICtrlCreateInput("", 98, 78, 135, 21)
$Inputsave4 = GUICtrlCreateInput("Aucune", 98, 106, 133, 21)
$Labelsave1 = GUICtrlCreateLabel("nom du contact", 10, 30, 78, 17)
$Labelsave2 = GUICtrlCreateLabel("telephone", 36, 54, 51, 17)
$labelsave3 = GUICtrlCreateLabel("adresse postale", 26, 82, 62, 17)
$Label1 = GUICtrlCreateLabel("Information", 10, 110, 78, 17)
$Button3 = GUICtrlCreateButton("sauvegarder", 236, 122, 67, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg1 = GUIGetMsg()
Switch $nMsg1
Case $GUI_EVENT_CLOSE
GUIDelete($Form2)
ExitLoop
Case $Button3
;enregistre dans le fichier.ini sous la forme : exemple si dessous
; [nom_du_contact]
; telephone = 0612345678
; mail = jean@mail.com
; adresse_postale = 2 rue des aoutiens
Dim $aData[3][2] = [ _
["telephone", GUICtrlRead($Inputsave2)], _
["adresse_postale", GUICtrlRead($Inputsave3)], _
["Information", GUICtrlRead($Inputsave4)]]
IniWriteSection($iniFile, GUICtrlRead($Inputsave1), $aData, 0)
Local $iIndex = _GUICtrlComboBox_AddString($Combo1, GUICtrlRead($Inputsave1))
_GUICtrlComboBox_SetCurSel($Combo1, $iIndex)
_Contact_Select(GUICtrlRead($Inputsave1))
GUIDelete($Form2)
ExitLoop
EndSwitch
WEnd
EndFunc ;==>_add_contact