Code : Tout sélectionner
;~ #include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
;~ Opt('MustDeclareVars', 1)
Global $hTreeView1, $a
$a = 2
GUIRegisterMsg($WM_NOTIFY, '_OnNotify')
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
_Main()
Func _Main()
Global $hItem, $hTreeView, $hItem2, $hItem3, $i1
Local $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
;~ Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView Add", 400, 600)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 600, $iStyle, $WS_EX_CLIENTEDGE)
$hTreeView1 = GUICtrlGetHandle(-1)
GUISetState()
_GUICtrlTreeView_BeginUpdate($hTreeView)
$hItem = _GUICtrlTreeView_Add($hTreeView, 0, "Imprimante 1 ")
_GUICtrlTreeView_AddChild($hTreeView, $hItem, "1 param 1")
_GUICtrlTreeView_AddChild($hTreeView, $hItem, "1 param 2")
_GUICtrlTreeView_AddChild($hTreeView, $hItem, "1 param 3")
_GUICtrlTreeView_AddChild($hTreeView, $hItem, "1 param 4")
_GUICtrlTreeView_AddChild($hTreeView, $hItem, "1 param 5")
$hItem2 = _GUICtrlTreeView_Add($hTreeView, 0, "Imprimante 2 ")
_GUICtrlTreeView_AddChild($hTreeView, $hItem2, "2 param 1")
_GUICtrlTreeView_AddChild($hTreeView, $hItem2, "2 param 2")
_GUICtrlTreeView_AddChild($hTreeView, $hItem2, "2 param 3")
_GUICtrlTreeView_AddChild($hTreeView, $hItem2, "2 param 4")
_GUICtrlTreeView_AddChild($hTreeView, $hItem2, "2 param 5")
$hItem3 = _GUICtrlTreeView_AddChild($hTreeView, $hItem2, "Imprimante 3 ")
_GUICtrlTreeView_AddChild($hTreeView, $hItem3, "2 param 1")
_GUICtrlTreeView_AddChild($hTreeView, $hItem3, "2 param 2")
_GUICtrlTreeView_AddChild($hTreeView, $hItem3, "2 param 3")
_GUICtrlTreeView_AddChild($hTreeView, $hItem3, "2 param 4")
_GUICtrlTreeView_AddChild($hTreeView, $hItem3, "2 param 5")
_GUICtrlTreeView_Expand($hTreeView)
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_SetChecked($hTreeView, $i1)
Global $hand
$hand = 0
Do
If $hand <> 0 Then
$hand = _GUICtrlTreeView_GetSelection($hTreeView)
;~ MsgBox(0, "niveau dans la branche =", _GUICtrlTreeView_Level($hTreeView, $hand))
$nombrebranche = _GUICtrlTreeView_Level($hTreeView, $hand)
If _GUICtrlTreeView_IsParent($hTreeView, _GUICtrlTreeView_GetParentHandle($hTreeView, $hand), $hand) Then
$parentport = _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetParentHandle($hTreeView, $hand))
Else
$parentport = _GUICtrlTreeView_GetText($hTreeView, $hand)
EndIf
$result = '"' & _GUICtrlTreeView_GetText($hTreeView, $hand) & '" est dans la branche de "' & $parentport & '"'
If $nombrebranche = 2 Then
$result = $result & '" et dans la branche de "' & _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetParentHandle($hTreeView, _GUICtrlTreeView_FindItem($hTreeView, $parentport)))
EndIf
MsgBox(0, "Nombre de branche = "&_GUICtrlTreeView_Level($hTreeView, $hand), $result)
;~ if _GUICtrlTreeView_GetChecked($hTreeView,$hand)=True Then
;~
;~ MsgBox(0,_GUICtrlTreeView_GetText ($hTreeView,$hand),"est checked"&@CRLF&"le parent est "&_GUICtrlTreeView_GetText ($hTreeView,_GUICtrlTreeView_GetParentHandle($hTreeView,$hand)))
;~ Else
;~ MsgBox(0,_GUICtrlTreeView_GetText ($hTreeView,$hand),"n'est pas checked"&@CRLF&"le parent est "&_GUICtrlTreeView_GetText ($hTreeView,_GUICtrlTreeView_GetParentHandle($hTreeView,$hand)))
;~ EndIf
$hand = 0
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func _OnNotify($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNM_TREEVIEW, $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWnd = $hWnd
$iMsg = $iMsg
$iwParam = $iwParam
If DllStructGetData($tNMHDR, 'hwndFrom') = $hTreeView1 Then
If DllStructGetData($tNMHDR, 'Code') = $TVN_SELCHANGEDW Then
$tNM_TREEVIEW = DllStructCreate($tagNMTREEVIEW, $ilParam)
If $a = 2 Then
;~
$hand = DllStructGetData($tNM_TREEVIEW, 'NewhItem')
;~
$a = 1
Else
$a = 2
EndIf
EndIf
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_OnNotify