怎么才能得到树控件叶子节点的父亲节点内容(已解决)
本帖最后由 andyloving 于 2012-8-6 22:07 编辑项目中需要对Autoit制作的树控件进行操作,但对这个控件用的不熟悉,这里麻烦大家给个方法。
怎么才能得到树控件叶子节点的父亲节点内容?
(因为树是动态产生的,没有具体对象来指向每一个叶子节点,目前就知道叶子节点的节点文本)
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
Dim $Item1, $Item2, $Item3
;Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
;Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel, $compinfo
;Local $togglebutton, $infobutton, $statebutton, $cancelbutton
;Local $msg, $item, $hItem, $text
#region ### START Koda GUI section ### Form=E:\AU3 study\档案管理软件\Demo\树搜索\Form1.kxf
$FrmTree = GUICreate("树查询", 169, 347, 614, 246, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
$TreeView= GUICtrlCreateTreeView(8, 8, 153, 329)
addTree()
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, 'MY_WM')
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func addTree()
For $i = 0 To 4
$Item1[$i] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] 爷爷", $i), $treeview)
For $j = 0 To 5
$Item2[$j] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] 爸爸", $j), $Item1[$i])
For $k = 0 To 5
GUICtrlCreateTreeViewItem(StringFormat("[%02d] 儿子", $k), $Item2[$j])
Next
Next
Next
EndFunc ;==>addTree
Func MY_WM($hWnd, $msg, $wParam, $lParam)
Local $tNMHdr = DllStructCreate($tagNMHDR, $lParam), $tNM_TREEVIEW
Local $hWndFrom = DllStructGetData($tNMHdr, 'hWndFrom')
Local $iIDFrom = DllStructGetData($tNMHdr, 'IDFrom')
Local $iCode = DllStructGetData($tNMHdr, 'Code')
If $iIDFrom = $treeview Then
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
If GUICtrlRead($treeview) > 0 Then
$ID1=Number(GUICtrlRead($treeview))
$Text1=GUICtrlRead($treeview, 1)
$Parent= _GUICtrlTreeView_GetParentParam($treeview,$ID1)
$ParentName= _GUICtrlTreeView_GetText($treeview,$Parent)
$Parent2= _GUICtrlTreeView_GetParentParam($treeview,$Parent)
$ParentName2= _GUICtrlTreeView_GetText($treeview,$Parent2)
MsgBox(0, 0, 'ID: ' & $ID1& @CRLF & 'Text: ' & $Text1&@CRLF&"Parent: "&$Parent&$ParentName&@CRLF&"Parent2:"&$Parent2&$ParentName2)
EndIf
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM
非常感谢,受教了! 受教了,很有用
页:
[1]