Solved

how to use lParam member variable in CTreeCtrl

Posted on 1998-02-27
7
840 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 10 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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