how to use lParam member variable in CTreeCtrl

 I'm creating an application which contains a CTreeCtrl such as Workspace in
DEVSTUDIO,  there is one member variable - lParam in each tree item, but i don't know
how to use it. I'm trying to store a CObList or a pointer to linklist into this lParam, but
how ? can anybody tell me please.
eugenengAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RONSLOWCommented:
The lParam is used to hold extra data.  If you use callbacks for tree node labels, then you'd usually make use of the data in the lParam from within the OnGetDispInfo callback.

To store a pointer in the lParam, use a cast eg.
  lParam = reinterpret_cast<LPARAM>(mypointer);
and likewise, to get the pointer back out of the lparam, use
  mypointer = reinterpret_cast<CObList*>(lParam);

Do you really want an entire list associated with a tree item, of just a single element of the list.  If only a single element is required, then you could store a pointer to that element in the lParam, or if you used an array, you could store the index into the array.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eugenengAuthor Commented:
Dear Ronslow :
 can you show me how to store in  and get out a CObject, or struct, frome a lparam then assign it to tree item. thank
0
RONSLOWCommented:
If you have CMyClass (maybe derived from CObject)
and you have a pointer to an object CMyClass* pMyObjectpMyObject,
then do this when creating the tree item...

treeitem.lParam = reinterpret_cast<LPARAM>(pMyObject);

Whenever you refer to a tre item (eg. use clicks on it an you want to know what is selected).  The get the corresponding item and do this...

CMyClass* pMyObject = reinterpret_cast<CMyClass*>(lParam);

You don't need to 'get out <something> from a lParam then assign it to tree item'.  You simply fill in the lParam when you create the tree item (along with label etc).  When you need to get at the object, you ask for (or are given) the tree item struct and look at lParam and cast it (as shown above).



0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

eugenengAuthor Commented:
Dear RONSLOW:
  Regarding the question of storing CObject pointer into TV_ITEM.lParam member variable of a tree control item, after i've new my a CObject pointer and attached it to lParam of TV_ITEM(by using the way you tough me), would the tree control clear the memory (that allocated for CObject) when tree item has been deleted?
0
RONSLOWCommented:
No - you manage the data yourself.

The tree (or list) control simply looks at it.

Of course, you could write you own code that also killed off the data.
0
eugenengAuthor Commented:
is the example below correctly remove the memory ? :

   CMyObjec* pMyStruct;
   pMyStruct = reinterpret_cast<CMyStruc*>(GetItemData(hTree));
   delete pMyStruct;


0
RONSLOWCommented:
It all depends on how you are creating and managing your data.

There code would delete the data associated - but you'd want to ensure that that doesn't result in any pointers getting stuffer. eg. if your CMyStruc objects are in a linked list (eg CList), and you just delete one of them, then that could stuff up your list.

But assuming that the tree is the only place that stores the data, then that would do it (assuming the GetItemData call and args are all OK).


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.