CTreeView & CTreeCtrl

//插入数据

 HTREEITEM hParent = m_TreeCtrl.InsertItem(_T("Root"),TVI_ROOT,TVI_LAST);
 HTREEITEM hChild1 = m_TreeCtrl.InsertItem(_T("Child1"),hParent);
 HTREEITEM hChild2 = m_TreeCtrl.InsertItem(_T("Child2"),hParent);

//展开树

m_TreeCtrl.SetItemState(hParent,TVIS_EXPANDED,TVIS_EXPANDED);或
m_TreeCtrl.Expand(hParent,TVE_EXPAND);(注:第一种一开始好像无法选中子项)

 //取得当前选中的Item

 HTREEITEM hSel = m_TreeCtrl.GetSelectedItem();
 m_TreeCtrl.InsertItem(_T("aaa"),hSel);           //在选中项下插入新的Item
 m_TreeCtrl.SetRedraw(TRUE);                      //刷新

 HTREEITEM hParent = m_TreeCtrl.GetRootItem();    //定位到根目录
 m_TreeCtrl.InsertItem(_T("Item"),hParent);       //在根目录下插入新项

//查找指定的Item

 CString str = _T("Child1");
 HTREEITEM hParent = m_TreeCtrl.GetRootItem();
 while (hParent!=NULL)
 {
  if (strcmp(m_TreeCtrl.GetItemText(hParent),str)==NULL)     //找到
  {
   break;
  }
  else
  {
   hParent = m_TreeCtrl.GetNextVisibleItem(hParent);      //查找下一Item
  }
 }

//动态创建一树型控件

 DWORD dwStyle = WS_CHILD |WS_VISIBLE | WS_BORDER | TVS_HASBUTTONS |TVS_HASLINES;
 m_Tree.Create(dwStyle,rcTree,this,0x00016);
 m_Tree.InsertItem(_T("Root"));

你可能感兴趣的:(null,border)