本文介绍了我如何检索ctreectrl MFC的LPARAM值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个树控件,其中每个节点都与一个LPARAM值相关联。在特定的按钮单击事件上,我想要检索LPARAM值。下面给出的代码执行不止一次。所以,当我试图检索初始值的LPARAM值时,它是一个垃圾值。



我尝试了什么:



I have a Tree Control where each node is associated with a LPARAM value. On a particular button click event I want to retrieve the LPARAM value. The below given code is executed more than once. so when i trying to retrieve the LPARAM value for the initial values its a garbage value.

What I have tried:

strTemp.Format(_T("%s %f %s %f"), _T("Length: "), fLength, _T("-->"), fCXLength);
m_strParamval = _T("LENG") + CXString::Format(_T("%d"), m_nMatID);
LPCTSTR pszParamVal = m_strParamval;

HTREEITEM hMatChild = m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM,strTemp, 0, 0, 0, 0, (LPARAM)pszParamVal, m_hMatNode, TVI_LAST);









这是检索的男女同校:







this is the coed for retrieving:

TVITEMEX item1;
item1.mask = TVIF_PARAM;
item1.hItem = m_hMatTest;


TreeView_GetItem(m_cTreeCtrl, &item1);
CString strPath1 = (LPCTSTR)item1.lParam;

推荐答案

CString strParamval = _T("LENG") + CXString::Format(_T("%d"), m_nMatID);
TCHAR *pszParamVal = new TCHAR[strParamval.GetLength()];
_tcscpy(pszParamVal, strParamval.GetString());

再次:当这样做时,不要忘记在删除项目或破坏树控件时删除内存。

Again: When doing so, don't forget to delete the memory when deleting items or destroying the tree control.


这篇关于我如何检索ctreectrl MFC的LPARAM值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 04:18