#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGUI = GUICreate('Treeview', 300, 300)
$Treeview1 = GUICtrlCreateTreeView(2, 2, 296, 296)
GUICtrlSetImage(-1, 'shell32.dll', 5)
$Fitem1 = GUICtrlCreateTreeViewItem('项目1', $Treeview1)
$Sitem1_1 = GUICtrlCreateTreeViewItem('项目1-1', $Fitem1)
$Sitem1_2 = GUICtrlCreateTreeViewItem('项目1-2', $Fitem1)
$Sitem1_3 = GUICtrlCreateTreeViewItem('项目1-3', $Fitem1)
GUICtrlSetState($Fitem1, $GUI_EXPAND)
$Fitem2 = GUICtrlCreateTreeViewItem('项目2', $Treeview1)
$Sitem2_1 = GUICtrlCreateTreeViewItem('项目2-1', $Fitem2)
$Sitem2_2 = GUICtrlCreateTreeViewItem('项目2-2', $Fitem2)
$Sitem2_3 = GUICtrlCreateTreeViewItem('项目2-3', $Fitem2)
GUICtrlSetState($Fitem2, $GUI_EXPAND)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Sitem1_1, $Sitem1_2, $Sitem1_3, $Sitem2_1, $Sitem2_2, $Sitem2_3
$iFitemID = _GUICtrlTreeView_GetParentParam($Treeview1, $nMsg)
$sItemText = _GUICtrlTreeView_GetText($Treeview1, $iFitemID)
MsgBox(0, '被点击项目ID = ' & $nMsg, '父项目ID = ' & $iFitemID & @CRLF & '父项目文本 = ' & $sItemText)
EndSwitch
WEnd
|