Click to See Complete Forum and Search --> : Weird problem with TreeView


MXPguru
September 25th, 2005, 01:56 PM
'tvh' holds the handle of the TreeView whose items' text I want to grab. The TreeView is of another application currently running. I get its handle through Spy++.

Check this code:


int tvhi;
tvhi = 0x000702A6;
HWND tvh;
tvh = (HWND)tvhi;

HTREEITEM tvroot;
tvroot = (HTREEITEM)SendMessage(tvh,TVM_GETNEXTITEM,TVGN_ROOT,0); // get root item

if(tvroot==NULL)
MessageBox(hWnd,"err1","asdf",MB_OK);

TVITEMEX itemobj;

itemobj.mask = TVIF_TEXT; // i've to retrieve text
itemobj.pszText = text;
itemobj.cchTextMax = 256;
itemobj.hItem = tvroot; // i've to work on root item

if(!SendMessage(tvh,TVM_GETITEM,0,(LPARAM)&itemobj)) // retrieve text
MessageBox(hWnd,"err2","asdf",MB_OK);
else
MessageBox(hWnd,itemobj.pszText,"asdf",MB_OK);

Now I'm getting the "err2" messagebox. If I send any other message, like to get number of items in treeview or to delete all items in treeview, it works fine. But if I do this to get text of the item, the SendMessage returns false.

Can anybody help, please?

kirants
September 26th, 2005, 01:34 AM
Sorry. I bring you some bad news :(

What you want is not possible in a simple way. Please look at this thread (http://www.codeguru.com/forum/showthread.php?t=291065&highlight=WM_GETTEXT) which talsk about a similar situation and the reason why it doesn't work.

It's good that you mentioned right away that the treeview is in another process :wave: Otherwise, people would be guessing ;)

MXPguru
September 26th, 2005, 03:40 AM
It's possible. Check this application: http://www.nirsoft.net/utils/sysexp.html

MXPguru
September 26th, 2005, 09:58 AM
Ok. You said it's not possible in a simple way. Thanks for your reply and your link to the article in the other thread.

kirants
September 26th, 2005, 12:31 PM
You are welcome..:wave: Please post if you have any problem.

kkez
September 26th, 2005, 01:58 PM
Look also at this article (http://www.codeproject.com/shell/ctrayiconposition.asp) from "Two ways to do it".

The point is:
The main reason is that we can't pass pointer to locally allocated TBBUTTON structure
to another process (process of Windows tray application). To solve this problem, we need to
allocate TBBUTTON structure inside tray application process. Then we can send message to
a toolbar with a pointer to that allocated memory, and at the end - we can read this block of
memory back to our application.

Of course replace TBBUTTON with TVITEMEX.
Should work with treeview too imho...but i didn't try :)