即整體移動某項到另一項作為其子項。
(被移動項還有自己的子項的),有沒有啥辦法?
類裡好像也沒啥相關的函數
這裡不需要實現拖拽,就類似於刪除某項後把其放入“回收站”項
遞歸復制再刪除
HTREEITEM hR;
void CMtapp1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
HTREEITEM hRoot = m_tree.InsertItem("My Computer");
HTREEITEM hC = m_tree.InsertItem("C:\\", hRoot);
HTREEITEM hD1 = m_tree.InsertItem("My Documents", hC);
HTREEITEM hCf1 = m_tree.InsertItem("doc1.doc", hC);
HTREEITEM hCf2 = m_tree.InsertItem("contract.txt", hC);
HTREEITEM hCf3 = m_tree.InsertItem("data.bin", hC);
HTREEITEM hCf4 = m_tree.InsertItem("simple.c", hC);
HTREEITEM hCf5 = m_tree.InsertItem("testpaper.docx", hD1);
HTREEITEM hD = m_tree.InsertItem("D:\\", hRoot);
HTREEITEM hDf1 = m_tree.InsertItem("backup.img", hD);
HTREEITEM hDf2 = m_tree.InsertItem("pic1.bmp", hD);
hR = m_tree.InsertItem("Recycle Bins", hRoot);
m_btn1.EnableWindow(FALSE);
}
void CMtapp1Dlg::MoveNode(HTREEITEM hP, HTREEITEM hS)
{
HTREEITEM h = m_tree.GetChildItem(hS);
while (h != NULL)
{
HTREEITEM hc = m_tree.InsertItem(m_tree.GetItemText(h), hP);
MoveNode(hc, h);
h = m_tree.GetNextItem(h, TVGN_NEXT);
}
}
void CMtapp1Dlg::OnButton2()
{
// TODO: Add your control notification handler code here
HTREEITEM hsel = m_tree.GetSelectedItem();
if (hsel != NULL && hsel != hR)
{
HTREEITEM h = m_tree.InsertItem(m_tree.GetItemText(hsel), hR);
MoveNode(h, hsel);
m_tree.DeleteItem(hsel);
}
m_tree.Expand(hR, TVE_EXPAND);
}