问题描述
i有关于树控件中插入项的查询,如下所述:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE
| TVIF_PARAM,strTemp,0,0,0,0,(LPARAM)( LPCTSTR)(LPCTSTR)strParamval,m_hMatNode,TVI_LAST);
插入strparamval
时iam检索数据我无法获得如下所述的数据:
TVITEMEX项目;
item.mask = TVIF_PARAM;
item.hItem = hChildItem;
TreeView_GetItem(m_cTreeCtrl,& item);
CString strParam =(LPCTSTR)item.lParam;
这是一个for循环所以很多次调用该函数。当我保持下面的代码时,它的工作原理如下:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE | TVIF_PARAM,strTemp,0 ,0,0,0,
(LPARAM)strParamval.AllocSysString(),
m_hMatNode,TVI_LAST);
但是这个逻辑是循环的,当我分配和sysfreestring上次给出错误的值时。
我的怀疑是什么?我们必须在这里做sysfreestring,因为它在for循环中?
我尝试过:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE | TVIF_PARAM,strTemp,0,0,0,0,
(LPARAM)strParamval。 AllocSysString(),
m_hMatNode,TVI_LAST);
Hi,
i have query regarding the insert item in tree control as mentioned below:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE
| TVIF_PARAM, strTemp, 0, 0, 0, 0, (LPARAM)(LPCTSTR)(LPCTSTR)strParamval, m_hMatNode, TVI_LAST);
the strparamval is inserted here
when iam retrieving the data iam not able to get the data as mentioned below:
TVITEMEX item;
item.mask = TVIF_PARAM;
item.hItem = hChildItem;
TreeView_GetItem(m_cTreeCtrl, &item);
CString strParam = (LPCTSTR)item.lParam;
this is a for loop so lot of times the function will be called. when i kept below code it worked as mentioned below:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE| TVIF_PARAM, strTemp, 0, 0, 0, 0,
(LPARAM)strParamval.AllocSysString(),
m_hMatNode, TVI_LAST);
but as this logic is loop when i allocate and sysfreestring its giving wrong value for last time.
my doubt is wether we have to do sysfreestring here as it is in for loop ?
What I have tried:
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE| TVIF_PARAM, strTemp, 0, 0, 0, 0,
(LPARAM)strParamval.AllocSysString(),
m_hMatNode, TVI_LAST);
推荐答案
CString *pStrParam = new CString(strParamval);
m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE |
TVIF_SELECTEDIMAGE| TVIF_PARAM, strItemText, 0, 0, 0, 0,
(LPARAM)pStrParam, m_hMatNode, TVI_LAST);
稍后删除该项:
To delete the item later:
TVITEMEX item;
item.mask = TVIF_PARAM;
item.hItem = hChildItem;
TreeView_GetItem(m_cTreeCtrl, &item);
CString *pStrParam = (CString*)item.lParam;
delete pStrParam;
删除控件后,必须对每个项目进行以上操作。
When the control is deleted, the above has to be done for each item.
这篇关于树控制中的Allocsysstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!