# Reading ListView32 and SysTreeView32 controls

## Recommended Posts

Latest additions to let you loop over all the items in a treeview:

HTREEITEM EXPORT GetTreeViewNameByItem(HWND hWnd, HTREEITEM hItem, char *szItemName)
{
if (!hItem)
{
*szItemName = '\0';
return 0;
}

// Open a handle to the remote process's kernel object
DWORD dwProcessId;
HANDLE hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, dwProcessId);
SneakyGetTreeItemName(hWnd, hItem, hProcess, szItemName, 100);

return hItem;
}

HTREEITEM EXPORT TreeViewGetRoot(HWND hWnd)
{
return (HTREEITEM) SendMessage(hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0);
}

HTREEITEM EXPORT TreeViewNextChild(HWND hWnd, HTREEITEM hItem)
{
return TreeView_GetNextItem(hWnd, hItem, TVGN_CHILD);
}

HTREEITEM EXPORT TreeViewNextSibling(HWND hWnd, HTREEITEM hItem)
{
return TreeView_GetNextItem(hWnd, hItem, TVGN_NEXT);
}

Autoit example code/ C++ wrappers:

Local $tree = GetActiveControl($title)

Local $root = TreeViewGetRoot($tree)
DumpTreeView($tree,$root)

Func DumpTreeView($tree,$node)
While $node Local$str = GetTreeViewNameByItem($tree,$node)
ConsoleWrite("node is " & $str & @LF); ExpandTreeViewItem($tree, $node) Local$child = TreeViewNextChild($tree,$node)
if $child <> 0 Then DumpTreeView($tree, $child) Local$node = TreeViewNextSibling($tree,$node)
WEnd
Endfunc

Func GetTreeViewNameByItem($hwnd,$hitem)
Local $str = "" Local$foo = DllCall($g_socdll, "long", "GetTreeViewNameByItem", "hwnd",$hwnd, "long", $hitem, "str",$str)
If @error Then
MsgBox(0, "Debug", "Error with DllCall(GetTreeViewNameByItem)")
Endif
Return $foo[3] Endfunc Func TreeViewGetRoot($hwnd)
Local $foo = DllCall($g_socdll, "long", "TreeViewGetRoot", "hwnd", $hwnd) If @error Then MsgBox(0, "Debug", "Error with DllCall(TreeViewGetRoot)") Endif Return$foo[0]
Endfunc

Func TreeViewNextChild($hwnd,$hitem)
Local $foo = DllCall($g_socdll, "long", "TreeViewNextChild", "hwnd", $hwnd, "long",$hitem)
If @error Then
MsgBox(0, "Debug", "Error with DllCall(TreeViewNextChild)")
Endif
Return $foo[0] Endfunc Func TreeViewNextSibling($hwnd, $hitem) Local$foo = DllCall($g_socdll, "long", "TreeViewNextSibling", "hwnd",$hwnd, "long", $hitem) If @error Then MsgBox(0, "Debug", "Error with DllCall(TreeViewNextSibling)") Endif Return$foo[0]
Endfunc

##### Share on other sites

I need TreeView control functions too.

All of that manipulating with TreeViews can be done by DllCall & SendMessage.

Only one thing is not possible this way: TreeViewGetItemText/TreeViewSetItemText

So I tried use C++ code from this topic a make simple DLL

only with one function TreeViewGetItemText

It's based on combination of GetTreeViewItemByName and SneakyGetTreeItemName (merged).

It's only for WIN NT/XP - not for WIN Me/9x

I tried to compile it in Dev-Cpp, but there was errors in standard include files.

So I compiled it in MSVC++ 2003 at my friend's computer.

But it seems to be some problem with this DLL

- when running dllcall there is error: listed procedure (in DLL) not found

I'm not so experienced in C++, so please can somebody help me with this?

Where is problem with compilation and/or running this DLL...

Here are my files:

DLL.CPP - source of DLL

DLL.H - header file of DLL

treeview_app.au3 - sample application with treeview (to be controled)

treeview_test.au3 - testing script (with dllcall for manipulating with treeview)

Win32_1.zip - compressed binary DLL

Edited by Zedna

##### Share on other sites

My problem is probably somewhere in project preferences in MSVC ,

because in compiled DLL is my function exported somehow strange.

Here is dump of exports from my DLL:

dumpbin.exe /exports Win32_1.dll

Microsoft ® COFF/PE Dumper Version 7.10.3077

Dump of file Win32_1.dll

File Type: DLL

Section contains the following exports for Win32_1.dll

00000000 characteristics

4378B8B6 time date stamp Mon Nov 14 17:17:58 2005

0.00 version

1 ordinal base

1 number of functions

1 number of names

ordinal hint RVA name

1 0 0001102D ?TreeViewGetItemText@@YAPAU_TREEITEM@@PAUHWND__@@PAU1@

Summary

4000 .data

1000 .idata

5000 .rdata

2000 .reloc

1F000 .text

10000 .textbss

So problem is that my function is not exported under name TreeViewGetItemText

but under name ?TreeViewGetItemText@@YAPAU_TREEITEM@@PAUHWND__@@PAU1@

Can somebody help me with this?

Thank you

##### Share on other sites

I'm not familiar with C++

but then i copied the code and tried compiling under Dev-C++ anyway

Gave up immediately when it returned me a whole bunch of errors, I didn't know what I was doing anyway

I'm just desperate for a SysTreeView functionality

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

##### Share on other sites

I'm not familiar with C++

but then i copied the code and tried compiling under Dev-C++ anyway

Gave up immediately when it returned me a whole bunch of errors, I didn't know what I was doing anyway

I'm just desperate for a SysTreeView functionality

In Dev-cpp are some strange versions of include files (*.h)

- undefined some types, structures, included nested include files which couldn't then be compiled.

In MSVC++ are all these header files correct, so the same code can be compiled without errors.

So maybe there is somewhere new version of header files for Dev-cpp, but I don't know.

So I'm still waiting for little help from somebody skilled in compiling this small piece of C++ code under Dev-cpp/MSVC++ (or other compiler).

Thank you

Edited by Zedna

##### Share on other sites

did you use the plugin_sdk environment under Extra to compile your dll plugin I think it is the best todo

##### Share on other sites

did you use the plugin_sdk environment under Extra to compile your dll plugin I think it is the best todo

When plugins appeared I looked into this plugins SDK, but now I forget about it.

I will look at it and try something.

At first look I think there is missing extern "C" before __declspec(dllexport)

in my dll.h.

Thank you very much for this good tip.

##### Share on other sites

Fur,

Have you posted or would you post a copy of the compiled DLL. I have tried to compile your code but the latest VC++ is having problems digesting it.

TIA

Todd

##### Share on other sites

Fur,

Have you posted or would you post a copy of the compiled DLL. I have tried to compile your code but the latest VC++ is having problems digesting it.

TIA

Todd

If your question was for me:

No I haven't done this my attepts to succefull finish

##### Share on other sites

If your question was for me:

No I haven't done this my attepts to succefull finish

Thanks Zedna.

I think by just sending the text for the option I want to select I can work around the problem for what I need to do right now. I just can't verify I'm on the correct options when I select them. I have found another tool called TextCatch that does successfully grab the info from a TreeView control and has a COM interface. I haven't tried to mate it to AutoIt yet. I'm going to use my work around for my 1.0 and I'll readdress the issue in 1.1.

Todd

##### Share on other sites

@tweast

Here is an other application that can grab text from a screen.

SnagIt

I am also looking for functions to grab text from non windows standard controls.

I was hoping AutoIT has a way into this, but I have not found it.

I understand that it is possible as long as they are standard controls, but non standard is not possible.

Nevertheless these applications are able to do so.

If someone can explain me why they can and we can't ?

regards

ptrex

##### Share on other sites

Working DLL

Please note that credit for this solution should be given to Fur.

Thanks to a friend that knows VC++ much better than I, we created a mostly working DLL. I have not had any crashes or errors generated, but the CopyTreeViewToClipboard function does not seem to work. I don't need that function for the project I'm working on now so I'll look into it at a future date.

I did a minor correction in the wrappers and I added an additional compound wrapper to select item by name.

I have only tested on WinXP and have not yet tested all the functions. Your mileage may vary. I do not suggest all of it will work on any system or any of it will work on all systems.

AutoItTreeViewExtension.dll

TreeView Testing.au3 (includes the wrappers)

TreeView_app.au3 (Provided by Zedna in an earlier post)

AutoItTreeViewExtension.dll

TreeView_Testing.au3

treeview_app.au3

##### Share on other sites

tweast GREAT!

Can you post here C++ source of this DLL?

Thanks.

##### Share on other sites

I have only tested on WinXP and have not yet tested all the functions. Your mileage may vary. I do not suggest all of it will work on any system or any of it will work on all systems.

Original code from this post is working only WIN NT/XP/200x (and not on WIN 9x/ME) due to diferent API functions on these platforms for VirtualAlloc/VirtualAllocEx and VirtualFree/VirtualFreeEx

For detailed diferences look into great _mem.au3 UDF here: MEM UDF

- functions _MemAlloc, _MemFree are there maded for both platforms.

Edited by Zedna

##### Share on other sites

I have only tested on WinXP

Works on a win98se

>"C:\PROGRAMMI\AUTOIT3\EXTRA\EDITORS\SCITE\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "C:\WINDOWS\TEMP\Treewiew test.au3" /autoit3dir "C:\Programmi\Autoit3\beta" /UserParams

>Running AU3Check C:\Programmi\Autoit3\Extra\Editors\SciTE\Defs\Unstable\Au3Check\au3check.dat

>AU3Check Ended. No Error(s).

>Running: (3.1.1.125):C:\Programmi\Autoit3\autoit3.exe "C:\WINDOWS\TEMP\Treewiew test.au3"

Tree/Root is 0

Item 21 is 0

Item 22 is 0

>AutoIT3.exe ended.

>Exit code: 0 Time: 2.880

Edited by Lapo

##### Share on other sites

Works on a win98se

You didn't run treeview_app.au3 which should be manipulated!

I ran this on my WIN98 SE and it's NOT working:

>"C:\PROGRAM FILES\AUTOIT3\SCITE\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "C:\PZ\AUTOIT\POK\TREEVIEW\!VirtualAllocEx\CPP\FORUM_DLL_OK\TreeView_Testing.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams

>Running AU3Check...C:\Program Files\AutoIt3\SciTe\Defs\Unstable\Au3Check\au3check.dat

>AU3Check Ended.

>Running: (3.1.1.67):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\PZ\AUTOIT\POK\TREEVIEW\!VirtualAllocEx\CPP\FORUM_DLL_OK\TreeView_Testing.au3"

Tree/Root is 0x00000314 4729764

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

node is þ³

Item 21 is 0

Item 22 is 0

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

Error calling SendMessage(TVIF_TEXT)

>AutoIT3.exe ended.

>Exit code: 0 Time: 4.703

##### Share on other sites

You didn't run treeview_app.au3 which should be manipulated!

I ran this on my WIN98 SE and it's NOT working:

You are right .. tested again clicked on treeview_app.au3 and run

Treewiew test.au3 in scite .. and same output as you .. but the items in

app.au3 are expadning .. same result in >> explorer.exe (C:\WINDOWS\EXPLORER.SCF)

changing \$title ="" in Treewiew test.au3

Edited by Lapo

##### Share on other sites

Any chance at all at exporting the functions so I can access them via COM?

##### Share on other sites

Working DLL

I have only tested on WinXP and have not yet tested all the functions. Your mileage may vary. I do not suggest all of it will work on any system or any of it will work on all systems.

I tested on WINXP also some of your untested functions and all OK:

CollapseTreeViewItem

GetSelectedTreeViewItem

Also note: SelectTreeViewItemByName - will expand parent if it's not expanded

Good work.

Now when things are working can be added also SetTreeViewNameByItem --> TVM_SETITEM instead of TVM_GETITEM (GetTreeViewNameByItem), but this is not so important as GetTreeViewNameByItem.

##### Share on other sites

The select tree does work fine, but how can i select things in a listview?

I am trying to make a script wich enables alot of policy settings.

I described my situatie at: http://www.autoitscript.com/forum/index.ph...topic=27426&hl=

Is there a way to do this?

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...