我有一个树形控件,我用两个节点启动树控件,其中两个节点由子节点组成。我在对话框中添加了一个按钮,现在当我单击任何根节点并单击此按钮时,我必须复制现有节点,即我复制现有节点。
我能够复制它并显示重复的数据。正是我的问题出现了,即,我无法看到复制的根节点文本,但我能够看到子节点,唯一的问题是根节点无法显示文本。
void AddCopy
{
int model_count = 2;
WCHAR szSelectedItemText[MAX_PATH] = {0};
WCHAR szChildItem[MAX_PATH] = {0};
WCHAR *szDuplicateItem;
HTREEITEM hFirstChild;
HTREEITEM hFirstChildTemp ;
HTREEITEM hParentSelect;
HTREEITEM hFirstSubChild ;
HTREEITEM hShareTempItem;
HTREEITEM hShareTemp;
HTREEITEM hChildParent;
HTREEITEM hPsChildItem ;
HTREEITEM hTreeNextItem;
hSelectedItem = m_TreeCtrl.GetNextItem((HTREEITEM)(m_TreeCtrl.GetSafeHwnd()),TVGN_CARET);
m_TreeCtrl.GetNextItem(hSelectedItem,TVGN_CARET);
if(hSelectedItem == NULL)
{
::MessageBox(NULL,L"No Item is hSelectedItem",L"Test",MB_OK|MB_ICONEXCLAMATION);
}
m_TreeCtrl.EnsureVisible(hSelectedItem);
::SendDlgItemMessage(m_TreeCtrl.GetSafeHwnd(),IDC_TREE,TVM_SELECTITEM,0,(LPARAM)hSelectedItem);
tvItem.mask = TVIF_TEXT;
tvItem.pszText = szSelectedItemText;
tvItem.cchTextMax = MAX_PATH;
tvItem.hItem = hSelectedItem;
tvItem.cChildren = 1;
m_TreeCtrl.GetItem(&tvItem);
szDuplicateItem = szSelectedItemText;
if(::wcsstr(szSelectedItemText,L"(")||::wcsstr(szSelectedItemText,L")"))
{
::MessageBox(NULL,L"Cannot Add Device On Replicated Model \n Please Choose An Appropriate Model",L"Test",MB_OK|MB_ICONERROR);
}
else
{
if(szSelectedItemText !=L"")
{
int count =0 ;
WCHAR szNextVisible[256]={0};
hTreeNextItem = m_TreeCtrl.GetNextSiblingItem(hSelectedItem);
while(hTreeNextItem!= NULL)
{
tvChildItem.mask = TVIF_TEXT;//TVITEM tvChildItem;
tvChildItem.pszText = szNextVisible;
tvChildItem.cchTextMax = MAX_PATH;
tvChildItem.hItem = hTreeNextItem;
m_TreeCtrl.GetItem(&tvChildItem);
m_TreeCtrl.GetNextVisibleItem(hTreeNextItem);
HTREEITEM hSibiling = TreeView_GetNextSibling(m_TreeCtrl.GetSafeHwnd(),hTreeNextItem);
if(::wcsstr(szNextVisible,szSelectedItemText))
{
if(::wcsstr(szNextVisible,L"("))
{
count++;
}
}
hTreeNextItem = hSibiling;
}
model_count = model_count + count;
}
WCHAR szTextSelectedItem[MAX_PATH]= {0};
hParentSelect = TreeView_GetParent(m_hTreeWnd,hSelectedItem);
HTREEITEM hDummy = m_TreeCtrl.GetParentItem(hSelectedItem);
tvInsert.hParent = hParentSelect;//TVINSERTSTRUCT tvInsert;
tvInsert.hInsertAfter = TVI_LAST;
tvInsert.item.pszText = szSelectedItemText;
tvInsert.item.hItem = hSelectedItem;
if((!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))&&
!(::wcsstr(szDuplicateItem,L"XXX"))))
{
hParentItem = m_TreeCtrl.InsertItem(&tvInsert);
hFirstChild = m_TreeCtrl.GetChildItem(hSelectedItem);
hFirstChildTemp = hFirstChild;
while (hFirstChild != NULL)
{
tvChildItem.mask = TVIF_TEXT;
tvChildItem.pszText = szChildItem;
tvChildItem.cchTextMax = MAX_PATH;
tvChildItem.hItem = hFirstChild;
tvChildItem.cChildren = 1;
m_TreeCtrl.GetItem(&tvChildItem);
if(hFirstChild == hSubChild)
{
tvInsert.hParent = hShareItemParent;
} else {
tvInsert.hParent = hParentItem;
}
tvInsert.hInsertAfter = TVI_LAST;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = szChildItem;
tvInsert.item.hItem = hFirstChild;
if(::wcsstr(szChildItem,L"XXX")||
::wcsstr(szChildItem,L"XXX")||
::wcsstr(szChildItem,L"XXX"))
{
hShareItemParent = m_TreeCtrl.InsertItem(&tvInsert);
hFirstSubChild = m_TreeCtrl.GetChildItem(hFirstChild);
hShareTemp = hFirstSubChild;
hChildParent = m_TreeCtrl.GetParentItem(hFirstChild);
while(hFirstSubChild != NULL)
{
tvChildItem.mask = TVIF_TEXT;
tvChildItem.pszText = szChildItem;
tvChildItem.cchTextMax = MAX_PATH;
tvChildItem.hItem =hFirstSubChild;
tvChildItem.cChildren = 1;
m_TreeCtrl.GetItem(&tvChildItem);
if(hFirstSubChild == hShareChildItem)
{
tvInsert.hParent = hShareTempItem;
}
else
{
tvInsert.hParent = hShareItemParent;
}
tvInsert.hInsertAfter = TVI_LAST;
tvInsert.item.pszText = szChildItem;
tvInsert.item.hItem = hFirstSubChild;
hShareTempItem = m_TreeCtrl.InsertItem(&tvInsert);
if(0 == ::wcscmp(szChildItem,L"YYY"))
{
hShareChildItem = m_TreeCtrl.GetChildItem(hFirstSubChild);
hFirstSubChild = hShareChildItem;
}
else
{
if(hShareChildItem == hFirstSubChild)
{
hFirstSubChild = hShareTemp;
}
hNextSibilingItem = m_TreeCtrl.GetNextSiblingItem(hFirstSubChild);
hFirstSubChild = hNextSibilingItem;
}
}
}
hPsChildItem = m_TreeCtrl.GetNextSiblingItem(hFirstChild);
hFirstChild = hPsChildItem;
}
::UpdateWindow(m_TreeCtrl.GetSafeHwnd());
}
}
}
这是我如何添加copy.For实例在我的树中第一个节点是XXX,现在我点击添加按钮,树控件获取另一个项目为XXX(2),依此类推..像这样
在我的情景中,当我添加时,我正在接受""空的东西作为节点,并能够获得子节点。现在再次点击添加我现在得到XXX(2)并再次添加XXX(3)。
我不知道为什么我在调试时无法获取文本显示文本但未设置。
任何人都可以让我知道我做错了什么。