Je vous transfert un code que je réalise actuellement, j'ai un souci avec la gestion du clic dans le switch lorsque les menus sont réalisés avec des Assigns. donc j'aimerai gérer le clic sur le menu clic droit d'un PC mais le programme boucle quand j'insère le 2ème morceau de code dans le Switch.Et je ne comprend pas du tout pourquoi, ça doit être tout bête.
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <listviewconstants.au3>
#include <GUITreeView.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
Global $rows, $nbrows, $nbcols, $idTreeView_1, $hTreeView_1, $rows2, $nbrows2, $nbcols2
Global $selection=0
Global $iTreeView_Flag = False
Local $sLocalSQLiteDll = "sqlite3.dll" ; to be change to an existing .dll to have no error
_SQLite_Startup()
$sqlite = _SQLite_Open(@ScriptDir & "\BDD_test.sqlite")
_SQLite_Exec(-1, 'CREATE TABLE IF NOT EXISTS PC(idPC INTEGER PRIMARY KEY AUTOINCREMENT, nomPC TEXT,ipPC TEXT,macPC TEXT,fonctionPC TEXT,versionPC TEXT,datepremierapp TEXT,datedernierapp TEXT,modelePC TEXT);')
_SQLite_Exec(-1, 'INSERT INTO PC VALUES ("1","Test1","10.185.1.109","01:02:03:04:05","STANDARD","2015.2.1.0","17/04/2015 à 10h00","17/04/2015 à 11h30","Dell");')
_SQLite_Exec(-1, 'INSERT INTO PC VALUES ("2","Test2","10.181.1.129","01:02:03:04:05","STANDARD","2015.2.1.0","17/04/2015 à 10h00","17/04/2015 à 11h30","HP");')
Global $iTreeView_Flag = False
#Region - GUI Create
$gui = GUICreate('GUI', 800, 600)
Local $infopc = GUICtrlCreateListView("Information du PC|colonne2", 400, 6, 394, 294, $LVS_NOCOLUMNHEADER, $LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth(-1, 0, 195)
_GUICtrlListView_SetColumnWidth(-1, 1, 195)
Local $idItem1 = GUICtrlCreateListViewItem("Modèle|", $infopc)
Local $idItem2 = GUICtrlCreateListViewItem("Fonction|", $infopc)
Local $idItem3 = GUICtrlCreateListViewItem("Version|", $infopc)
Local $idItem4 = GUICtrlCreateListViewItem("Adresse IP|", $infopc)
Local $idItem5 = GUICtrlCreateListViewItem("Adresse MAC|", $infopc)
Local $idItem6 = GUICtrlCreateListViewItem("Date première connexion|", $infopc)
Local $idItem7 = GUICtrlCreateListViewItem("Date dernière connexion|", $infopc)
$TreeView1 = GUICtrlCreateTreeView(6, 6, 394, 588, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT), $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle($TreeView1)
Local $idlieu = GUICtrlCreateTreeViewItem("Lieu", $TreeView1)
Local $idlieu1 = GUICtrlCreateTreeViewItem("Lieu 1", $idlieu)
Local $idlieu2 = GUICtrlCreateTreeViewItem("Lieu 2", $idlieu)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
#EndRegion - GUI Create
_SQLite_GetTable2d(-1, "SELECT * FROM PC ORDER BY nomPC;", $rows, $nbrows, $nbcols)
For $i = 1 To $nbrows
$ipadresse = StringSplit($rows[$i][2], ".")
Select
Case $ipadresse[2] = "185"
Assign("PC" & $rows[$i][1], GUICtrlCreateTreeViewItem($rows[$i][1], $idlieu1))
Case $ipadresse[2] = "181"
Assign("PC" & $rows[$i][1], GUICtrlCreateTreeViewItem($rows[$i][1], $idlieu2))
EndSelect
Assign("menuPC" & $rows[$i][1], GUICtrlCreateContextMenu(Eval("PC" & $rows[$i][1])))
Assign("pingPC" & $rows[$i][1], GUICtrlCreateMenuItem("Ping " & $rows[$i][1], Eval("menuPC" & $rows[$i][1])))
Next
GUICtrlSetState($idlieu, $GUI_EXPAND)
;~ GUICtrlSetState($TreeView1,$GUI_HIDE)
#Region - GUI SelectLoop
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
If $iTreeView_Flag Then
$iTreeView_Flag = False
$selection = _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView))
;~ ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF)
If StringLeft($selection, 1) = "T" And StringLen($selection) = 5 Then
_SQLite_GetTable2d(-1, "SELECT * FROM PC WHERE nomPC='" & $selection & "'", $rows2, $nbrows2, $nbcols2)
GUICtrlSetData($idItem4, "|" & $rows2[1][2])
GUICtrlSetData($idItem5, "|" & $rows2[1][3])
GUICtrlSetData($idItem2, "|" & $rows2[1][4])
GUICtrlSetData($idItem3, "|" & $rows2[1][5])
GUICtrlSetData($idItem6, "|" & $rows2[1][6])
GUICtrlSetData($idItem7, "|" & $rows2[1][7])
GUICtrlSetData($idItem1, "|" & $rows2[1][8])
EndIf
EndIf
WEnd
;Second Try, it's work for the list view item, and it work for the treeview items too but it returned wrong value :(.
;the value returned is the selected item before new item selected/clicked
;i've checked the $tagNMTREEVIEW, but there isn't same with the $tagNMLISTVIEW, there is no item param.
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $IdFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$IdFrom = DllStructGetData($tNMHDR, "IdFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hTreeView
Switch $iCode
Case $NM_CLICK
$iTreeView_Flag = True
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY► Afficher le texte
Case Eval("pingterminal"&$selection)
msgbox(0,"","Ping "&$selection)
msgbox(0,"","Ping "&$selection)
merci pour votre aide.


