下面能添加也能删除:
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
$a = StringSplit('a|b|c|d|e|f|g|tj', '|', 1)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_RCLICK ; The user has clicked the right mouse button within the control
Local $iPos_X = _WinAPI_GetMousePosX(True, $hWndTreeview)
Local $iPos_Y = _WinAPI_GetMousePosY(True, $hWndTreeview)
Local $hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iPos_X, $iPos_Y)
_GUICtrlTreeView_SelectItem($hWndTreeview, $hItem)
$Index = GUICtrlRead($hTreeView, 1)
For $x = 1 To 10
$Indexa = StringFormat("[%02d] text", $x)
If $Index = $Indexa Then
Local $iID = GUICtrlRead($hTreeView)
GUICtrlCreateTreeViewItem('tj_text', $iID)
_GUICtrlTreeView_Expand($hTreeView, $iID)
EndIf
Next
For $y = 1 To 8
$Indexb = StringFormat($a[$y] & '_text', $y)
If $Index = $Indexb Then
If $hItem Then _GUICtrlTreeView_Delete($hWndTreeview, $hItem)
EndIf
Next
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|