找回密码
 加入
搜索
查看: 2005|回复: 3

[GUI管理] 怎么才能得到树控件叶子节点的父亲节点内容(已解决)

[复制链接]
发表于 2012-8-6 19:06:24 | 显示全部楼层 |阅读模式
本帖最后由 andyloving 于 2012-8-6 22:07 编辑

项目中需要对Autoit制作的树控件进行操作,但对这个控件用的不熟悉,这里麻烦大家给个方法。
怎么才能得到树控件叶子节点的父亲节点内容?
(因为树是动态产生的,没有具体对象来指向每一个叶子节点,目前就知道叶子节点的节点文本)
发表于 2012-8-6 20:18:10 | 显示全部楼层

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Dim $Item1[10], $Item2[10], $Item3[10]
;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
 楼主| 发表于 2012-8-6 22:06:53 | 显示全部楼层
非常感谢,受教了!
发表于 2013-8-2 16:01:24 | 显示全部楼层
受教了,很有用
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-9 13:34 , Processed in 0.078634 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表