[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how to use lParam member variable in CTreeCtrl

Posted on 1998-02-27
7
Medium Priority
?
846 Views
Last Modified: 2013-11-20
 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.
0
Comment
Question by:eugeneng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 20 total points
ID: 1316649
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
 

Author Comment

by:eugeneng
ID: 1316650
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1316651
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:eugeneng
ID: 1316652
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1316653
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
 

Author Comment

by:eugeneng
ID: 1316654
is the example below correctly remove the memory ? :

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


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1316655
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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question