Solved

how to use lParam member variable in CTreeCtrl

Posted on 1998-02-27
7
813 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
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 10 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:eugeneng
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now