C
C
Cyapa2013-10-24 13:11:02
API
Cyapa, 2013-10-24 13:11:02

WInAPI and TVirtualStringTree

My respects, gentlemen. I had a chance to write a program to interact with someone else's software. This software has a TVirtualStringTree control from which you need to get text. And now, as they say, "And what I just haven't tried." With this control it is impossible to do anything at all. Google does not help, similar problems did not find a solution.

What I have tried:
- Get the root of this tree

  RootTree := SendMessage(HandleTree, TVM_GETNEXTITEM, TVGN_ROOT, 0);

There are no problems here. The tree gladly gives its root.

- Open the process that contains the tree
  GetWindowThreadProcessID(HandleTree, @ProcessID);
  ProcessHanlde := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID);

Again, there were no problems.

- Allocate memory for TV_ITEM in an open process
  PItem := VirtualAllocEx(ProcessHanlde, nil, SizeOf(TV_ITEM), MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);

And again everything is smooth.

— Fill in the TV_ITEM structure
  with LItem do
  begin
    hItem := HTreeItem(RootTree);
    mask := TVIF_HANDLE;
  end;

I hope it's right.

— Write this structure to the allocated memory of an open process
  WriteProcessMemory(ProcessHanlde, PItem, @LItem, SizeOf(LItem), Dummy);

Everything is recorded normally, 40 is returned to Dummy.

- Get a structure describing Root
  if TreeView_GetItem(HandleTree, PItem^) then
  begin
    ReadProcessMemory(ProcessHanlde, PItem, @LItem, SizeOf(LItem), Dummy);
  end;

And here is a complete disappointment, the macro always returns False. What have I done wrong? Where did you go wrong?

I also tried to get other Items besides root:
  SomeItem := SendMessage(HandleTree, TVM_GETNEXTITEM, TVGN_CHILD, RootTree);

but they are not. Or the tree carefully hides them.

Even just removing the root does not work. What to do?

The tree on which I'm testing all this looks like this: There are
image

very strong suspicions that all these problems are related to the structure of the tree.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question