I am working to automate several applications. One depends on the output of another.
The problem I am running into is that when I try to access the Treeview
to get additional info, the count returns 0.
If I look at it visibly, it show quite a few items. If I look at it with Winspector, it reports 0 visible items.
How can I gather this info? This is the info that is gathered dynamically and from several places. I cannot access the databases (that would be nice, but since some of the info is dynamic, it is not possible).
Here is the output that Winspector gives me:
Properties for window: 0x00021806
Class Name: SysTreeView32
Rectangle: 213, 180, 1038, 375
Size: 825, 195
Client Rectangle: 0, 0, 821, 191
Client Size: 821, 191
Styles: WS_CHILD,
WS_VISIBLE,
WS_CLIPSIBLINGS,
WS_CLIPCHILDREN,
WS_TABSTOP,
StylesEx: WS_EX_NOPARENTNOTIFY,
WS_EX_CLIENTEDGE,
WS_EX_LEFT,
WS_EX_LTRREADING,
WS_EX_RIGHTSCROLLBAR
ID: 0
Properties: Atom: #43288 0xFFFFFFFF (-1)
Class specific: Visible items:0,
Total items: 0
Window is Ansi
Owner EXE c:\csg\acsr\XBOI.EXE
Any ideas how I can retrieve the node info and i开发者_如何学JAVAtems? I am using VBA (access) with API calls with sendmessage.
Here is my code that I am using to test item count:
Sub testtree(mytv As Long)
Dim z As Long
Dim wClass As String, wText As String
Dim hWndTvw As Long
Dim hNode As Long
Dim varReturn As Long
Dim tvcount As Long
Dim hchild As Long
Dim j As Integer
hchild = mytv
wClass = Space(64)
j = GetClassName(hchild, wClass, 63)
wClass = Left(wClass, j)
wText = Space(256)
j = SendMessageS(hchild, WM_GETTEXT, 255, wText)
wText = Left(wText, j)
Debug.Print wText
z = SendMessage(mytv, TVM_GETCOUNT, 0&, 0&)
MsgBox z
End Sub
Thanks!
You should consider using TVM_GETNEXTITEM message to enumerate the tree's nodes: first call it with TVGN_ROOT flag to get the root node, then use TVGN_CHILD and TVGN_NEXT flags to walk through the nodes. This message returns you the item's handle.
When you've got the item's handle, use TVM_GETITEM message to retrieve the associated data you're interested in (e.g. item's text).
You should read that 2 links carefully for more info on using that messages.
P.S. The problem is, the TVM_GETITEM message uses TVITEM structure with pointers, and I'm not sure it'll be easy to use from the VBA (unlike e.g. C, C++, even C#/VB.NET is IMO more suitable for that). In the worst case (i.e. unless you know something about the VBA I'm not aware of: last time I've dealt with VBA was about 2004), you'll need to develop a small COM object using C++/ATL for this single task, and redistrubute & register it along with your software. Or look for the 3-rd party components.
精彩评论