?
Solved

Getting proper lParam value out of the selected treeview item when it is right clicked

Posted on 2003-03-11
2
Medium Priority
?
296 Views
Last Modified: 2013-12-03
I want to retrieve the lParam value stored in the tree view item when the item is right clicked. When any item is right clicked, the value stored in the last item is retrieved.

I have written the code as follows-

While storing the value -

TVITEM tvi;
TVINSERTSTRUCT tvins;
HTREEITEM hSelected = NULL;
HTREEITEM hNew = NULL;

tvi.mask = TVIF_PARAM | TVIF_TEXT | TVIF_HANDLE;
tvi.pszText = lpszItem;
tvi.cchTextMax = lstrlen(lpszItem);
tvi.lParam = (LPARAM) lpszParam;
tvins.item = tvi;
hSelected = TreeView_GetSelection(hTree);
tvins.hInsertAfter = hSelected;
tvins.hParent = hSelected;
TreeView_InsertItem(hTree, (LPTVINSERTSTRUCT) &tvins);

While retrieving the value in the WM_NOTIFY -
HTREEITEM hCurrent = NULL;
TVITEM tvi;
LPSTR lpszItem = NULL;
LPNMHDR pnmh = (LPNMHDR) lParam;

if ((pnmh->code == NM_RCLICK) && (pnmh->idFrom == ID_TREE_VIEW_CONTROL)) {
hCurrent = TreeView_GetSelection(hTree);
tvi.hItem = hCurrent;
tvi.mask = TVIF_PARAM;
TreeView_GetItem(hTree, &tvi);
lpszItem = (LPSTR) tvi.lParam;
}

Would be glad of help. Thankyou.
0
Comment
Question by:Deodhar
[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
2 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 300 total points
ID: 8110495
LParam is only a 32 bit value.
You are assinging a string to that without allocating. So each time you assigning value to the same to "tvi.lParam = (LPARAM) lpszParam;" overwrites the previous string value.

So you have to allocate the string before you use InsertItem
like
char *psz = new char[length];
lstrcpy(psz, "Whatever");
tvi.lParam = (LPARAM) psz;

in order to avoid memory leak you have to add these to an array, or delete the string after use by traversing the tree...


Good Luck
0
 

Author Comment

by:Deodhar
ID: 8110844
Thank you. I have just started writing code for windows SDK and couldn't have solved it on my own. Thank you for the speedy reply.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

765 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