External TreeView using madRemote

Posted on 2003-03-17
Medium Priority
Last Modified: 2010-04-04
Hi all,

I have followed another thread http://search.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20272830.html to its logical conclusion by madshi, and have realised this is where I am falling over.

I am trying to read the nodes of an external systreeview32, given an hWnd. I need the final code to work on all Win platforms, so would prefer to use madRemote to stop the lock to NT platforms only. Would like a code example similar to the one mentioned on the thread above, but which will examine an external process and return the text from the treeview, using madRemote.

External app is Kazaa, if that helps narrow it down... trying to read Upload/Download treeviews.

500 points available.

Question by:Javen
  • 4
  • 4
LVL 20

Accepted Solution

Madshi earned 2000 total points
ID: 8167182
This code only gives you the parent items, but it should be a good start to dig yourself into this stuff.

Regards, Madshi.

uses CommCtrl, madRemote;

procedure ReadTreeView(tv: dword);
var i1      : integer;
    ti      : TTvItem;
    pti     : PTvItem;
    pid, ph : dword;
    c1      : dword;
    arrCh   : array [0..MAX_PATH] of char;
  GetWindowThreadProcessID(tv, pid);
  ph := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
  if ph <> 0 then begin
    pti := AllocMemEx(sizeOf(ti) + MAX_PATH, ph);
    ZeroMemory(@ti, sizeOf(ti));
    dword(ti.pszText) := dword(pti) + MAX_PATH;
    ti.cchTextMax := MAX_PATH;
    ti.hItem := TreeView_GetFirstVisible(tv);
    for i1 := 0 to integer(TreeView_GetVisibleCount(tv)) - 1 do begin
      if WriteProcessMemory(ph, pti, @ti, sizeOf(ti), c1) and
         TreeView_GetItem(tv, pti^) and
         ReadProcessMemory(ph, pti, @ti, sizeOf(ti), c1) and
         ReadProcessMemory(ph, ti.pszText, @arrCh, MAX_PATH, c1) then
        MessageBox(0, arrCh, 'item found', 0);
      ti.hItem := TreeView_GetNextVisible(tv, ti.hItem);
    FreeMemEx(pti, ph);

Author Comment

ID: 8186645
Hi madshi,

Once I have resolved my issues with using madRemote (cheers for your comments on the other thread), I shall test this out.

Hang on, and I'll get back to you soon...


Author Comment

ID: 8201506
Hi madShi/all,

In order to clarify, I am trying to get the information out of a Kazaa download/upload window. The code you have given above works, but no text is returned. I have used Spy++ to monitor the messages sent to the application, and this is what I've found...

1) GetNextItem returns hItem
2) GetItem returns the pointer to a TV_ITEM, which has the following...

hItem : as obtained
state : TVIS_CUT | TVIS_EXPANDED | 77E16880
pszText : 0000110A
plus some other bits and bobs

I am guessing that the reason the string is not returning anything is because the treeview has multiple columns, and multiple text items in it.

If someone is able to help me more, I am willing to push the points up to 1000.


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 20

Expert Comment

ID: 8201564
>> I am guessing that the reason the string is not returning anything is because the treeview has multiple columns, and multiple text items in it.

But does the first column not contain any text? You should get the text of the first column, if the code works correctly.

I don't have Kazaa installed (and I rather don't want to install it), so I can't really test it with that application. Perhaps you can try the code on some normal treeviews? Does it work on e.g. the Explorer's treeview?

Maybe Kazaa uses custom drawing, then we have a problem.

Author Comment

ID: 8201630
>> I don't have Kazaa installed (and I rather don't want to install it)

Don't blame you, at the moment, I am wishing I'd never heard of it either.

I am trying to test the code with another mini-app to get the data from Explorer.

Heres one question though...

I cut your code about to fit it into my program and replaced the "ph" with the process handle of the main window. Is this wrong? Does the treeview have a seperate process? This could be where I am going wrong.

Also, I am passing the tv : DWORD the handle of the treeview, is this correct?

LVL 20

Expert Comment

ID: 8201658
"tv" is meant to be the handle of the treeview, that's correct. Why did you replace "ph"? My code gets the "ph" directly from the "tv" handle, so there should be no need to change it. Anyway, you *can* replace it, if you do it right. It should be the process handle which owns the tree view. And no, the tree views are not seperate processes.

Author Comment

ID: 8201725
Hi madShi,

Cheers for all that... I have managed to get the code working, and read the contents of an Explorer TreeView. I tried this with Kazaa, and I still get nothing.

The Kazaa treeview is very complex and has multiple columns, holding different textual values, and one which has a progressbar within it.

The possibility is that it does use Custom Drawing, which I know nothing about.

There is another thread, which you have participated in which covers hooking text out using madCodeHook. Could this be another way for me to go...


LVL 20

Expert Comment

ID: 8201744
Hooking TextOut is an option, but that's really hard to do. Anyway, you can try. In that case please use the latest beta version:


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Integration Management Part 2
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question