TreeView怎么获取父项id
本帖最后由 qsy666888 于 2014-7-31 12:55 编辑我看了以前的水木子大侠的示例,但我还是没有弄出来
http://61.153.183.105/thread-44332-1-1.html
我提到的这种跟水木子大侠的示例似同非同,一直没有弄出来,不知道用什么代码去获取这种情况的id。
在此感谢谢大大们对我的耐心的帮助。#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Local $ini, $htv, $csname = "class", $hClass = 0
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $Form1 = GUICreate("获取父项id及文本示例", 216, 358, 525, 139)
Global $htv = GUICtrlCreateTreeView(8, 8, 201, 337, -1, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
readinfo("data.ini", $htv)
Do
Sleep(10)
Until GUIGetMsg() = -3
Func readinfo($ini, $htv, $csname = "class", $hClass = 0)
If Not $hClass Then $hClass = $htv
$aSec = IniReadSection($ini, $csname)
If @error Then Return False
For $i = 1 To $aSec
$child = IniReadSection($ini, $aSec[$i])
If @error Then;频道
$hItem = GUICtrlCreateTreeViewItem($aSec[$i], $hClass)
Else;子类
$hClass1 = GUICtrlCreateTreeViewItem($aSec[$i], $hClass)
readinfo($ini, $hClass, $aSec[$i], $hClass1)
EndIf;频道或分类
Next
Return True
EndFunc ;==>readinfo
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
;Dim $bb,$cc
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom
Case $htv
Switch $Event
Case $TVN_SELCHANGEDW
$ix = GUICtrlRead($htv)
If $ix > 0 Then
$aa =GUICtrlRead($ix,1)
MsgBox(0,'被点击的文本','被点击的文本' & $aa &',父项文本是:' & ',父项ID是:')
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc;==>WM_NOTIFY
回复 1# qsy666888 #include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUITreeView.au3>
Local $ini, $treeview, $hTreeView
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $Form1 = GUICreate("获取父项id及文本示例", 216, 358, 525, 139)
Global $treeview = GUICtrlCreateTreeView(8, 8, 201, 337, -1, $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle(-1)
GUISetState(@SW_SHOW)
readinfo("data.ini", $treeview)
Do
Sleep(10)
Until GUIGetMsg() = -3
Func readinfo($ini, $htv, $csname = "class", $hClass = 0)
If Not $hClass Then $hClass = $htv
$aSec = IniReadSection($ini, $csname)
If @error Then Return False
For $i = 1 To $aSec
$child = IniReadSection($ini, $aSec[$i])
If @error Then;频道
$hItem = GUICtrlCreateTreeViewItem($aSec[$i], $hClass)
Else;子类
$hClass1 = GUICtrlCreateTreeViewItem($aSec[$i], $hClass)
readinfo($ini, $hClass, $aSec[$i], $hClass1)
EndIf;频道或分类
Next
Return True
EndFunc ;==>readinfo
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tNMHDR, $IDFrom, $code
Local $iPos_X, $iPos_Y, $uFlags
$tNMHDR = DllStructCreate($tagNMHDR, $LParam)
$IDFrom = DllStructGetData($tNMHDR, "IDFrom")
$code = DllStructGetData($tNMHDR, "Code")
Switch $code
Case $NM_CLICK ; 点击鼠标左键
If $IDFrom = $treeview Then ; 点击 TreeView 控件时,获取点击到的控件句柄
$iPos_X = _WinAPI_GetMousePosX(True, $hTreeView)
$iPos_Y = _WinAPI_GetMousePosY(True, $hTreeView)
$uFlags = _GUICtrlTreeView_HitTest($hTreeView, $iPos_X, $iPos_Y)
If BitAND($uFlags, $TVHT_ONITEM) Then
Local $hItem, $hParent, $sText_I, $sText_P = '无父项目'
$hItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iPos_X, $iPos_Y)
MsgBox(0, '', _GUICtrlTreeView_GetTree($hTreeView, $hItem))
$sText_I = _GUICtrlTreeView_GetText($treeview, $hItem)
$hParent = _GUICtrlTreeView_GetParentHandle($hTreeView, $hItem)
If $hParent Then $sText_P = _GUICtrlTreeView_GetText($treeview, $hParent)
MsgBox(0, '父项目:' & $sText_P, '子项目:' & $sText_I)
EndIf
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
回复 2# user3000
user3000大侠,父项的 id 能不能获取 回复 3# qsy666888
_GUICtrlTreeView_GetParentParam
有了句柄,还要ID来作什么?
还有,你应该要多花一些时间和耐心去观看帮助的众多示例, 多多测试之! 回复 4# user3000
我想获取它的id来展开指定的父项,我试过好多代码,必须要父项的id才行 回复 4# user3000
我想获取它的id来展开指定的父项,我试过好多代码,必须要父项的id才行
这些疑难杂症,我们这些鼠辈肯定弄不出来 回复 4# user3000
还是没有弄得出来,哎!谢谢你 回复 7# qsy666888
_GUICtrlTreeView_GetParentParam
此函数可以获取到父项目的ID,如果有父项目的吧! 回复 8# user3000
我试过了,不得行 回复 9# qsy666888
你把下面代码加入到2楼代码的51行后面测试. Local $Id_P = _GUICtrlTreeView_GetParentParam($hTreeView, $hItem)
MsgBox(0, '父项目ID(0为根项目):' & $Id_P, GUICtrlRead($Id_P, 1))发觉很难与你交流;似乎是我在提问?!你还有问题,应该详细描述出来吧,单单回个"不行",算是什么回事呢! 回复 10# user3000
谢谢谢谢,不好意思,心里太着急了 回复 11# qsy666888
别急!这些东西急不来的,。
参考函数:_GUICtrlTreeView_Expand
页:
[1]