Link to home
Start Free TrialLog in
Avatar of sundeep07_er
sundeep07_er

asked on

Want to get the item text of a treeiew in another application

Hi experts,
I browsed through various soloutions given in ee , but none had a complete solution .Kindly help me with a source code to get the item text of a treeview control which is in another application running on win 2000.I have already posted this question once but none replied.

I want to loop through all the nodes in the treeview and retreive the text of each item and store it in an array .

pls help
Avatar of georg74
georg74

hi,
treeview control can be used in different ways and the solution depends on that. first question is if it is "owner drawn". if yes, then only it's application knows about the data (the text). the same applies to list boxes etc. ((you can still read it out, but you will need a simple OCR along with more comlicated control if you want to fully automate the process. It is possible to do that - it's about 3-4 days of work for experienced programmer, I've done that once.))

if no - much better case - then you can get the items by sending TVM_ messages to the control. ((I'd estimate that task to 1-3 hrs for exp. programmer))

practically, you need to do the following:

- use a window inspector (like WinSight) to find out how to get to the handle of the control and get the real handle to experiment with
- having the handle of the control, use TVM_GETNEXTITEM to get the root item handle (use TVGN_ROOT flag)
- also use TVM_GETNEXTITEM to get some subsequent item's handles
- use TVM_GETITEM along with item handle to get information about an item
- at this point, you will find out if you're getting some text from the control or not, and you'll get the idea how to get all of them.

HTH,
georg

PS: if you need help with a distinct part of the code, please be more specific.
Avatar of sundeep07_er

ASKER

Hi
tnx very much.but Ihave browsed through ee and understood that a "GPF" ERROR occures whenever a tvm_getitem is used .(I have seen the target app.crash .)
how to avoid this,how to access the memory of another process, and stuff like that are what I want to know

please help.I have been searching for a complete solution for a long time but in vain.
> a "GPF" ERROR occures whenever a tvm_getitem is used

that is surely not true, as this is the only way to get item information.

> how to access the memory of another process

generally speaking, by putting it in debug mode.
but of what use would it be?

if the information you want is visible on the screen, you can copy it from there.

please give us some background information, perhaps there is an workaround.

in the meantime, test if you can get the handle of that treeview control and test if
you can get the root item handle from it.

good luck,
georg
hey sundeep for the gpf.. (i doubt it though) did you allocate the the memory for the string if you are reteriving the text of each node? in other words when using TVIF_TEXT flag?

for reading other programs's memory you need to open the process and then you can use ReadProcessMemory, hey georg i dont think we need to go to debug mode for this... your thoughts!??

Have fun,
Pratap
hello pratap,
I did not write any code for getting the text of a treeview item.But always wanted to.
So to learn things I browsed  ee and found its a real tough task (for me!) since i am very very new to vb .

please refer

https://www.experts-exchange.com/questions/20096218/Getting-text-from-treeview-from-outside.html?query=text+of+a+treeview+item+in+another+application&clearTAFilter=true

the expert who answered ,
says  

 " For Windows NT/2000/xp:
Allocate memory in the treeview process address space using pMem=VirtualAllocEx(). Use pMem as a buffer for  TreeView_GetItem(). You can write and read pMem using ReadProcessMemory/WriteProcessMemory.

a) Obtain process id of B by GetWindowThreadProcessId(hTV,&pid)

b) Get the process handle of B by OpenProcess(PROCESS_VM_WRITE| PROCESS_VM_OPERATION | PROCESS_VM_READ)"


how do i do these thing? its all greek and latin.


please help one more time.
thanks!


SOLUTION
Avatar of pratap_r
pratap_r
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sundeep,

unfortunately, vb is not an adequate language for doing this.

I don't think (but I'm not sure if) it is really necessary to allocate the space for retuned data in the conxtext of the owner process.

read my first comment again and try these steps.

- first use some window inspector to get informatiln about controls in that window and about this specific control.

- second, try to send a simple TVM_GETCOUNT message to it (use the current handle obtained with the window inspector), and check the result. It should contain the count of the items in that treeview. (Read in your on-line help about the SendMessage function.)

try to accomplish these two steps first. there is no need to reserve any memeory, get process id or handle etc. after that, you will know much more and you will be in much better position to decide what to do next.

good luck,
georg
georg,

the call fails if you dont allocate the memory.. TVM_GETCOUNT will succeed though.. since its just a dword return value, its when passing the structure and the string buffer that the call fails, you can check my code if you want to.. it will fail at the TVM_GETITEM call

Have fun,
pratap
it seems that the problem is following:

the tree control is created with the option not to store item properties.
when it needs item properties, it sends a message to the controls window function.
the target application receives the message, and it tries to
use the passed pointer to the TVITEM structure (and text buffer). since the pointed memory
belongs to another application, access is denied and an access violation exception is thrown.
if the target app doesn't catch the exception it will "crash".

so, to access items of treeview controls created in such way,
it is necessary to create a buffer that is accessible
by the target application. it would not have to be in its space.

georg
georg, is there any other way to make a memory address accessible to a target application (for which we dont have the source)? apart from its own memory?

Thanks
Pratap
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
georg, not on the lines of these question but.. when  you dont control the target application launching the target app as a child process and having it inherit the handles .. how good will that be? ultimately at one point we will have to deal with the target's memory space

Have fun
Pratap
Thanks very much george and pratap.
I have hope now.
I understood the concept.I will study more on this and get back to u guys 'cause I know I can't do this without any expert's help

Tnx very much.
Sandeep, did you find a viable solutions to do this. This is something i am trying to do, would be great if you could share your discovered solution.

Thanks