Jayson Posted September 3, 2010 Share Posted September 3, 2010 Hello everyone, I'm trying to save and load some color for my ListView but I ran into a problem. Here it is : If I change the color of one of them ($CT or $CTB) by the popup menu it get saved perfectly but if none of them or both are changed everything goes wrong when i'm saving. I'm not sure how I could solve this. Any help would be appreciated Here's the code : expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <GuiMenu.au3> #include <Constants.au3> Global $Data = "Database.ini", $LireINIi = IniReadSection($Data, "Info"), $LireINIc = IniReadSection($Data, "Couleur"), $CT, $CTB $dll = DllOpen("user32.dll") $GUI = GUICreate("Bottin téléphonique personnel", 510, 450) $NVT = _GUICtrlListView_Create($GUI, "", 5, 5, 500, 347) _GUICtrlListView_SetExtendedListViewStyle($NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_BORDERSELECT)) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Adresse", 130, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Ville", 113, 2) _GUICtrlListView_InsertColumn($NVT, 3, "Téléphone", 100, 2) If $LireINIi <> 1 Then For $i = 1 To $LireINIi[0][0] $LisNom = $LireINIi[$i][0] $AdresseVilleTele = StringSplit($LireINIi[$i][1], "|") $LisAdresse = $AdresseVilleTele[1] $LisVille = $AdresseVilleTele[2] $LisTelephone = $AdresseVilleTele[3] _GUICtrlListView_AddItem($NVT, $LisNom,$i - 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisAdresse, 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisVille, 2) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisTelephone, 3) Next EndIf If $LireINIc <> 1 Then For $j = 1 To $LireINIc[0][0] $CTexteBk = $LireINIc[$j][0] ;"8421631"=0 $CTexte = $LireINIc[$j][1] ;8421631="0" _GUICtrlListView_SetBkColor($NVT, $CTexteBk) _GUICtrlListView_SetTextColor($NVT, $CTexte) _GUICtrlListView_SetTextBkColor($NVT,$CTexteBk) Next EndIf GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) ExitLoop EndSwitch WEnd Func SauveTout() If FileExists($Data) Then FileDelete($Data) EndIf If $CTB = "" Then IniWrite($Data, "Couleur", $LireINIc[1][0], $CT) EndIf If $CT = "" Then IniWrite($Data, "Couleur", $CTB, $LireINIc[1][1]) EndIf If $CTB = "" And $CT = "" Then IniDelete($Data, "Couleur") IniWrite($Data, "Couleur", $LireINIc[1][0], $LireINIc[1][1]) EndIf If $CTB <> $LireINIc[1][0] And $CT <> $LireINIc[1][1] Then IniDelete($Data, "Couleur") IniWrite($Data, "Couleur", $CTB, $CT) EndIf EndFunc ;==>SauveTout Func ListView_RClick() Local $Texte = 1, $TexteBk = 2, $Sauvegarder = 3 $Menu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur du texte", $Texte) _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur d'arrière-plan", $TexteBk) _GUICtrlMenu_AddMenuItem($Menu, "Sauvegarder", $Sauvegarder) Switch _GUICtrlMenu_TrackPopupMenu($Menu, $NVT, -1, -1, 1, 1, 2) Case $Texte $CT = _ChooseColor() _GUICtrlListView_SetTextColor($NVT, $CT) Case $TexteBk $CTB = _ChooseColor() _GUICtrlListView_SetBkColor($NVT, $CTB) _GUICtrlListView_SetTextBkColor($NVT, $CTB) Case $Sauvegarder SauveTout() EndSwitch _GUICtrlMenu_DestroyMenu($Menu) EndFunc ;==>ListView_RClick Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $NVT Switch $iCode Case $NM_RCLICK ListView_RClick() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Database.ini : [Info] a=a|a|a b=b|b|b [Couleur] 8421631=0 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 3, 2010 Moderators Share Posted September 3, 2010 Jayson,It is failing because if you do not have the ini file, your $LireINIc array does not get filled and throws an error when you try to compare $CT and $CTB with its elements. I suggest you declare the array as Global initially and then try to read the ini file to fill it, setting some default values if the read fails so that you have valid array elements for the compare lines. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jayson Posted September 3, 2010 Author Share Posted September 3, 2010 (edited) Melba,I don't get any error by reading the ini file or loading the color from the file. I only have a problem when it comes to save them. The $CT, $CTB and $LireINIc, are declared as Global in the first line of the script.Global $Data = "Database.ini", $LireINIi = IniReadSection($Data, "Info"), $LireINIc = IniReadSection($Data, "Couleur"), $CT, $CTBThen $LireINIc became array by thisIf $LireINIc <> 1 Then For $j = 1 To $LireINIc[0][0] $CTexteBk = $LireINIc[$j][0] ;Color for textbg & bg $CTexte = $LireINIc[$j][1] ;Color text _GUICtrlListView_SetBkColor($NVT, $CTexteBk) _GUICtrlListView_SetTextColor($NVT, $CTexte) _GUICtrlListView_SetTextBkColor($NVT,$CTexteBk) Next EndIfI just don't know how to save the data correctly in Func SauveTout()Changing only $CT or $CTB works when i save everything.I only got a problem when nothing is changed or both of 'em are changed. I also tried to set some value but it still not workingSorry for my english. Edited September 3, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 4, 2010 Moderators Share Posted September 4, 2010 Jayson,Let me try and explain again: You are declaring the arrays and filling them at the same time in this line:Global $Data = "Database.ini", $LireINIi = IniReadSection($Data, "Info"), $LireINIc = IniReadSection($Data, "Couleur"), $CT, $CTBIf there is no [Couleur] section in the ini, then $LireINIc is only declared as a simple variable (value = 1) rather than an array. This is exactly what you would expect if there was no [Couleur] section and is stated in the Help file. You obviously know this because you have code later in your script to cover this eventuality.Loading a fixed number of values like this from an ini file section is fraught with danger. What happens if not all the elements are present? What if they are not in the expected order? You do get errors when you save if the array is not fully loaded because you try to use the elements later in the code - even if they do not exist! Much better coding practice would be to use variables and read them directly from the ini file using the "default" parameter to cover the case of a missing value:$CT = IniRead($Data, "Couleur", "Texte", 0) ; Default black $CBT = IniRead($Data, "Couleur", "Arriere", 0xFFFFFF) ; Default whiteNow you have no problems with an array to reference later in your script when you save. Which brings us on to your SauveTout() function.You have compeletly misunderstood how an ini file is structured. You need to read the Help file pages again!Why do you delete the file each time? You do realise that you will lose all the address data as well I take it? And there is no need to delete values before replacing them - all you need to do is to overwrite the existing data, AutoIt does the rest for you!So your function need only look like this:Func SauveTout() IniWrite($Data, "Couleur", "Arriere", $CBT) IniWrite($Data, "Couleur", "Texte", $CT) EndFunc ;==>SauveToutNote that you save both colours every time, even if you have only changed one.All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jayson Posted September 6, 2010 Author Share Posted September 6, 2010 Melba, Sorry i misunderstood your earlier post You have always the right solution and I always try the hard/stupid way to make my stuff running. Now i understand perfectly what you mean't and everything works great Thx alot for your nice help Melba !! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 Jayson, My pleasure! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jayson Posted September 6, 2010 Author Share Posted September 6, 2010 May i ask your help again Melba ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 Jayson, That is why I am here! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jayson Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) Okay, here we go I got another problem when i'm using my menu popup(using Ajouter) from my listview to lunch InfoGUI().When I try to display another GUI it works great but when i'm adding a While into that function it crash everything.I tried some workaround but it still fail.expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <GuiMenu.au3> #include <Constants.au3> #include <array.au3> ; for debugging Global $Data = "Database.ini", $LireINIi = IniReadSection($Data, "Info") Global $CT = IniRead($Data, "Couleur", "Texte", 0) Global $CBT = IniRead($Data, "Couleur", "Arriere", 0xFFFFFF) Global $aLV_Click_Info, $hTmp_Edit = 0, $fDblClk = False $dll = DllOpen("user32.dll") $GUI = GUICreate("Bottin téléphonique personnel", 510, 450) $NVT = _GUICtrlListView_Create($GUI, "", 5, 5, 500, 347) _GUICtrlListView_SetExtendedListViewStyle($NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_BORDERSELECT)) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Adresse", 130, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Ville", 113, 2) _GUICtrlListView_InsertColumn($NVT, 3, "Téléphone", 100, 2) _GUICtrlListView_SetBkColor($NVT, $CBT) _GUICtrlListView_SetTextColor($NVT, $CT) _GUICtrlListView_SetTextBkColor($NVT,$CBT) If $LireINIi <> 1 Then For $i = 1 To $LireINIi[0][0] $LisNom = $LireINIi[$i][0] $AdresseVilleTele = StringSplit($LireINIi[$i][1], "|") $LisAdresse = $AdresseVilleTele[1] $LisVille = $AdresseVilleTele[2] $LisTelephone = $AdresseVilleTele[3] _GUICtrlListView_AddItem($NVT, $LisNom,$i - 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisAdresse, 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisVille, 2) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisTelephone, 3) Next EndIf GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 If $hTmp_Edit <> 0 Then ; If a temporary edit exists If _IsPressed("0D", $dll) Then ; If ENTER pressed $sText = GUICtrlRead($hTmp_Edit) ; Set label to edit content _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1]) GUICtrlDelete($hTmp_Edit) ; Delete temporary edit $hTmp_Edit = 0 EndIf EndIf If $fDblClk Then ; If an item was double clicked $fDblClk = False GUICtrlDelete($hTmp_Edit) ; Delete any existing temporary edits $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Read current text of clicked label Switch $aLV_Click_Info[1] ; Get label position Case 0 ; On Item $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2) Case Else ; On SubItem $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) EndSwitch $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 5, $aLV_Rect_Info[1] + 5, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit GUICtrlSetState($hTmp_Edit, $GUI_FOCUS) EndIf $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE DllClose($dll) ExitLoop EndSwitch WEnd Func SauveTout() For $i = 0 To _GUICtrlListView_GetItemCount($NVT) - 1 $LisNom = _GUICtrlListView_GetItemText($NVT, $i, 0) $LisAdresse = _GUICtrlListView_GetItemText($NVT, $i, 1) $LisVille = _GUICtrlListView_GetItemText($NVT, $i, 2) $LisTelephone = _GUICtrlListView_GetItemText($NVT, $i, 3) IniWrite($Data, "Info", $LisNom, $LisAdresse & "|" & $LisVille & "|" & $LisTelephone) Next IniWrite($Data, "Couleur", "Arriere", $CBT) IniWrite($Data, "Couleur", "Texte", $CT) EndFunc ;==>SauveTout Func ListView_RClick() Local $Ajouter = 1, $Supprimer = 2 , $Effacer = 3, $Sauvegarder = 4, $Texte = 5, $TexteBk = 6 $Menu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($Menu, "Ajouter", $Ajouter) _GUICtrlMenu_AddMenuItem($Menu, "Supprimer", $Supprimer) _GUICtrlMenu_AddMenuItem($Menu, "Effacer tout", $Effacer) _GUICtrlMenu_AddMenuItem($Menu, "") _GUICtrlMenu_AddMenuItem($Menu, "Sauvegarder", $Sauvegarder) _GUICtrlMenu_AddMenuItem($Menu, "") _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur du texte", $Texte) _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur d'arrière-plan", $TexteBk) Switch _GUICtrlMenu_TrackPopupMenu($Menu, $NVT, -1, -1, 1, 1, 2) Case $ajouter GUISetState(@SW_HIDE, $GUI) InfoGUI() Case $supprimer _GUICtrlListView_DeleteItemsSelected($NVT) Case $effacer _GUICtrlListView_DeleteAllItems($NVT) Case $Sauvegarder SauveTout() Case $Texte $CT = _ChooseColor() _GUICtrlListView_SetTextColor($NVT, $CT) Case $TexteBk $CBT = _ChooseColor() _GUICtrlListView_SetBkColor($NVT, $CBT) _GUICtrlListView_SetTextBkColor($NVT, $CBT) EndSwitch _GUICtrlMenu_DestroyMenu($Menu) EndFunc ;==>ListView_RClick Func InfoGUI() $GUI1 = GUICreate("Informations", 311, 105) GUICtrlCreateLabel("Nom", 38, 7, 22, 20) $nom1 = GUICtrlCreateInput("", 70, 5, 170, 20) GUICtrlCreateLabel("Adresse", 22, 32, 38, 20) $adresse1 = GUICtrlCreateInput("", 70, 30, 170, 20) GUICtrlCreateLabel("Ville", 41, 57, 19, 20) $ville1 = GUICtrlCreateInput("", 70, 55, 170, 20) GUICtrlCreateLabel("Téléphone", 9, 82, 51, 20) $telephone1 = GUICtrlCreateInput("", 70, 80, 170, 20) $Ajoute = GUICtrlCreateButton("Ajouter", 243, 4, 65, 47) $Annule = GUICtrlCreateButton("Annuler", 243,54, 65, 47) GUISetState() While 1 Switch GUIGetMsg() Case $ajoute ConsoleWrite("BDFG") EndSwitch WEnd ;$nom1 = InputBox("Nom", "Veuillez inscrire le nom de la personne à ajouter.", "", " M75") ;$adresse1 = InputBox("Adresse", "Veuillez inscrire l'adresse où la personne demeure.", "", " M75") ;$ville1 = InputBox("Ville", "Veuillez inscrire la ville où elle vie.", "", " M75") ;$telephone1 = InputBox("Numéro de téléphone", "Veuillez inscrire le numéro de téléphone de la personne.", "1-234-567-8900", " M14") ;$iIndex = _GUICtrlListView_GetItemCount($NVT) ;If $iIndex = -1 Then $iIndex = 0 ;_GUICtrlListView_AddItem($NVT, $Nom1, $iIndex) ;_GuiCtrlListView_AddSubItem($NVT, $iIndex, $Adresse1, 1) ;_GUICtrlListView_AddSubItem($NVT, $iIndex, $Ville1, 2) ;_GUICtrlListView_AddSubItem($NVT, $iIndex, $Telephone1, 3) EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $NVT Switch $iCode Case $NM_RCLICK ListView_RClick() Case $NM_DBLCLK $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited September 6, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 (edited) Jayson,You have a problem because you are waiting within a popup menu. As soon as you have selected something, the menu tries to close and it cannot because you are blocking it with your InfoGUI. Solution: Use a flag just as in GUIRegisterMsg. Look for the <<<<<<<<<<<<<<<<<< lines: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <GuiMenu.au3> #include <Constants.au3> #include <array.au3> ; for debugging Global $Data = "Database.ini", $LireINIi = IniReadSection($Data, "Info") Global $CT = IniRead($Data, "Couleur", "Texte", 0) Global $CBT = IniRead($Data, "Couleur", "Arriere", 0xFFFFFF) Global $aLV_Click_Info, $hTmp_Edit = 0, $fDblClk = False, $fInfoGUI = False ; <<<<<<<<<<<<<<<<<<< $dll = DllOpen("user32.dll") $GUI = GUICreate("Bottin téléphonique personnel", 510, 450) $NVT = _GUICtrlListView_Create($GUI, "", 5, 5, 500, 347) _GUICtrlListView_SetExtendedListViewStyle($NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT)) _GUICtrlListView_InsertColumn($NVT, 0, "Nom", 140, 2) _GUICtrlListView_InsertColumn($NVT, 1, "Adresse", 130, 2) _GUICtrlListView_InsertColumn($NVT, 2, "Ville", 113, 2) _GUICtrlListView_InsertColumn($NVT, 3, "Téléphone", 100, 2) _GUICtrlListView_SetBkColor($NVT, $CBT) _GUICtrlListView_SetTextColor($NVT, $CT) _GUICtrlListView_SetTextBkColor($NVT, $CBT) If $LireINIi <> 1 Then For $i = 1 To $LireINIi[0][0] $LisNom = $LireINIi[$i][0] $AdresseVilleTele = StringSplit($LireINIi[$i][1], "|") $LisAdresse = $AdresseVilleTele[1] $LisVille = $AdresseVilleTele[2] $LisTelephone = $AdresseVilleTele[3] _GUICtrlListView_AddItem($NVT, $LisNom, $i - 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisAdresse, 1) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisVille, 2) _GUICtrlListView_AddSubItem($NVT, $i - 1, $LisTelephone, 3) Next EndIf GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 If $hTmp_Edit <> 0 Then ; If a temporary edit exists If _IsPressed("0D", $dll) Then ; If ENTER pressed $sText = GUICtrlRead($hTmp_Edit) ; Set label to edit content _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1]) GUICtrlDelete($hTmp_Edit) ; Delete temporary edit $hTmp_Edit = 0 EndIf EndIf If $fDblClk Then ; If an item was double clicked $fDblClk = False GUICtrlDelete($hTmp_Edit) ; Delete any existing temporary edits $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Read current text of clicked label Switch $aLV_Click_Info[1] ; Get label position Case 0 ; On Item $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2) Case Else ; On SubItem $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) EndSwitch $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 5, $aLV_Rect_Info[1] + 5, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit GUICtrlSetState($hTmp_Edit, $GUI_FOCUS) EndIf ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $fInfoGUI = True Then $fInfoGUI = False InfoGUI() EndIf ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE DllClose($dll) ExitLoop EndSwitch WEnd Func SauveTout() For $i = 0 To _GUICtrlListView_GetItemCount($NVT) - 1 $LisNom = _GUICtrlListView_GetItemText($NVT, $i, 0) $LisAdresse = _GUICtrlListView_GetItemText($NVT, $i, 1) $LisVille = _GUICtrlListView_GetItemText($NVT, $i, 2) $LisTelephone = _GUICtrlListView_GetItemText($NVT, $i, 3) IniWrite($Data, "Info", $LisNom, $LisAdresse & "|" & $LisVille & "|" & $LisTelephone) Next IniWrite($Data, "Couleur", "Arriere", $CBT) IniWrite($Data, "Couleur", "Texte", $CT) EndFunc ;==>SauveTout Func ListView_RClick() Local $Ajouter = 1, $Supprimer = 2, $Effacer = 3, $Sauvegarder = 4, $Texte = 5, $TexteBk = 6 $Menu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_AddMenuItem($Menu, "Ajouter", $Ajouter) _GUICtrlMenu_AddMenuItem($Menu, "Supprimer", $Supprimer) _GUICtrlMenu_AddMenuItem($Menu, "Effacer tout", $Effacer) _GUICtrlMenu_AddMenuItem($Menu, "") _GUICtrlMenu_AddMenuItem($Menu, "Sauvegarder", $Sauvegarder) _GUICtrlMenu_AddMenuItem($Menu, "") _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur du texte", $Texte) _GUICtrlMenu_AddMenuItem($Menu, "Changer couleur d'arrière-plan", $TexteBk) Switch _GUICtrlMenu_TrackPopupMenu($Menu, $NVT, -1, -1, 1, 1, 2) Case $Ajouter $fInfoGUI = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $Supprimer _GUICtrlListView_DeleteItemsSelected($NVT) Case $Effacer _GUICtrlListView_DeleteAllItems($NVT) Case $Sauvegarder SauveTout() Case $Texte $CT = _ChooseColor() _GUICtrlListView_SetTextColor($NVT, $CT) Case $TexteBk $CBT = _ChooseColor() _GUICtrlListView_SetBkColor($NVT, $CBT) _GUICtrlListView_SetTextBkColor($NVT, $CBT) EndSwitch _GUICtrlMenu_DestroyMenu($Menu) EndFunc ;==>ListView_RClick Func InfoGUI() $GUI1 = GUICreate("Informations", 311, 105) GUICtrlCreateLabel("Nom", 38, 7, 22, 20) $nom1 = GUICtrlCreateInput("", 70, 5, 170, 20) GUICtrlCreateLabel("Adresse", 22, 32, 38, 20) $adresse1 = GUICtrlCreateInput("", 70, 30, 170, 20) GUICtrlCreateLabel("Ville", 41, 57, 19, 20) $ville1 = GUICtrlCreateInput("", 70, 55, 170, 20) GUICtrlCreateLabel("Téléphone", 9, 82, 51, 20) $telephone1 = GUICtrlCreateInput("", 70, 80, 170, 20) $Ajoute = GUICtrlCreateButton("Ajouter", 243, 4, 65, 47) $Annule = GUICtrlCreateButton("Annuler", 243, 54, 65, 47) GUISetState() While 1 Switch GUIGetMsg() Case $Ajoute ConsoleWrite("BDFG") Case $Annule GUIDelete($GUI1) EndSwitch WEnd ;$nom1 = InputBox("Nom", "Veuillez inscrire le nom de la personne à ajouter.", "", " M75") ;$adresse1 = InputBox("Adresse", "Veuillez inscrire l'adresse où la personne demeure.", "", " M75") ;$ville1 = InputBox("Ville", "Veuillez inscrire la ville où elle vie.", "", " M75") ;$telephone1 = InputBox("Numéro de téléphone", "Veuillez inscrire le numéro de téléphone de la personne.", "1-234-567-8900", " M14") ;$iIndex = _GUICtrlListView_GetItemCount($NVT) ;If $iIndex = -1 Then $iIndex = 0 ;_GUICtrlListView_AddItem($NVT, $Nom1, $iIndex) ;_GuiCtrlListView_AddSubItem($NVT, $iIndex, $Adresse1, 1) ;_GUICtrlListView_AddSubItem($NVT, $iIndex, $Ville1, 2) ;_GUICtrlListView_AddSubItem($NVT, $iIndex, $Telephone1, 3) EndFunc ;==>InfoGUI Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $NVT Switch $iCode Case $NM_RCLICK ListView_RClick() Case $NM_DBLCLK $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT) If $aLV_Click_Info[0] <> -1 Then $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYAll clear? M23Edit: Typnig! Edited September 6, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Jayson Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) Yes, everything's clear !! You're the Melba.Edit : I had to add an ExitLoop on both Case $Ajoute & $Annule to make the main gui fonctionnal after adding the data. Edited September 6, 2010 by Jayson Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 Jayson, Well, I have to leave you with something to do! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now