访问 SysTreeView32 的子节点 [英] Access child nodes of SysTreeView32

查看:90
本文介绍了访问 SysTreeView32 的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在 挂钩子类之后的下一个问题VBE窗口的SysTreeView32

我现在可以访问 SysTreeView32,但无法访问 hNode 的子节点.我尝试了许多变体,并在过去 2 小时内一直在阅读有关它的内容,但我无法解决.这甚至可能吗?由于不同的窗口尺寸和位置,我真的很想避免 mouse_event 和单击,但如果这是唯一的方法,那么我会尝试实现它.

This is my next question following Hook into a child class SysTreeView32 of VBE window

I can access the SysTreeView32 now but I cant access the child node of the hNode. I have tried many variations and been reading about it for the past 2 hours but I can't work it out. Is this even possible? I really want to avoid the mouse_event and clicking because of different window dimensions and position but if thats the only way then I will try to implement that.

代码如下:

Option Explicit

Private Const TVE_COLLAPSE = &H1
Private Const TVE_COLLAPSERESET = &H8000
Private Const TVE_EXPAND = &H2
Private Const TVE_EXPANDPARTIAL = &H4000
Private Const TVE_TOGGLE = &H3
Private Const TV_FIRST = &H1100
Private Const TVM_EXPAND = (TV_FIRST + 2)
Private Const TVM_GETNEXTITEM = (TV_FIRST + 10)
Private Const TVGN_ROOT = &H0
Private Const TVGN_NEXTVISIBLE = &H6
Private Const TVGN_CHILD = 4

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
                              (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                                    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Sub CollapseProjects()
   Dim hWndVBE As Long, hWndPE As Long, hWndTvw As Long, hNode As Long, varReturn
   hWndVBE = FindWindowEx(0, 0, "wndclass_desked_gsk", Application.VBE.MainWindow.Caption)
   hWndPE = FindWindowEx(hWndVBE, 0, "PROJECT", vbNullString)
   hWndTvw = FindWindowEx(hWndPE, 0, "SysTreeView32", vbNullString)

   Dim childNode As Long
   hNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_ROOT, 0&)
   childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
   Debug.Print "childNode " & childNode

   Do While hNode <> 0
      Debug.Print hNode
      varReturn = SendMessage(hWndTvw, TVM_EXPAND, TVE_COLLAPSE, hNode)
      hNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, hNode)
   Loop
End Sub

以及为什么

childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)
Debug.Print "childNode " & childNode

它总是返回0?

推荐答案

这个:

childNode = SendMessage(hNode, TVM_GETNEXTITEM, 0&, 0&)

不要求子节点.首先,您将消息发送到 hNode,而不是树控件,这完全没有意义.然后,要获取子节点,您需要在wParam 中传递TVGN_CHILD 标志,即0x4.您还需要在 lParam 中传递您想要其子项的项目.

Is not asking for a child node. Firstly, you're sending the message to hNode, not the tree control, which makes no sense at all. Then, to get the child node, you need to pass the TVGN_CHILD flag, which is 0x4, in wParam. You also need to pass the item you want the child of in lParam.

所以它可能看起来像这样:

So it would probably look something like this:

childNode = SendMessage(hWndTvw, TVM_GETNEXTITEM, TVGN_CHILD, hNode)

请参阅文档 用于 TVM_GETNEXTITEM 消息以获取更多信息.

See the docs for the TVM_GETNEXTITEM message for more information.

这篇关于访问 SysTreeView32 的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆