Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to translate a HTREEITEM or TVITEM to a Nodes collection index

Status
Not open for further replies.

MKuiper

Programmer
Jan 29, 2002
364
NL
Situation :
- a VB app which contains a treeview (mscomctl.ocx) on a form
- a C++ dll which is subclassing the treeview

When the C++ dll receives a message, like TVM_SELECTITEM, it receives a HTREEITEM which identifies the node.
I can get a TVITEM structure of the node at this point, that gives me additional information, including the lParam field, which seems to be unique for each node.

I need the subclass to call ocx-methods on the node. This requires me to know the key or index of the node in the Nodes collection.
Her is the problem, I can't figure out how to get the key or index of the node from the HTREEITEM or lParam.

Any help greatly appreciated,

Marcel
 
Got it.

DWORD ptr = (DWORD)GlobalLock ( (HGLOBAL)lParam );
if ( ptr != 0 )
{ ptr += 88; // Seems to be on offset 88 of some structure
IDispatch * pNode = (IDispatch *)ptr;
// pNode is a pointer to the Node object of interest
//
// do something with the node
//
GlobalUnlock ( (HGLOBAL)lParam ); }

Marcel
 
If there is no direct access struct available, imagen MS "improving" the data stored in lParam.. Yes - your code is gonna go BOOM ;) this way of "hacking" is about "use at your own risk", so you better be looking for a function to retrieve the IDispatch from a node. If it's not there, then it is not meant to be, and therefore can be removed, moved or changed any time. Just a notice, gl :)

------------------
When you do it, do it right.
 
You're right, but I must take the risk unless somebody comes up with something better. Fortunately it seems quite unlikely that Microsoft is going to improve mscomctl.ocx sooner or later.

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top