TreeCtrl 查找功能的最简单实现

    技术2022-05-11  57

     CString str = "Sam"; // 要查找的字符串

     HTREEITEM hRoot = m_tc.GetRootItem(); HTREEITEM hTemp; while (hRoot != NULL) {  if (m_tc.ItemHasChildren(hRoot))  {   hTemp = m_tc.GetNextItem(hRoot, TVGN_CHILD);   while(hTemp != NULL)   {    hTemp = m_tc.GetNextItem(hTemp, TVGN_NEXT);    CString &str = m_tc.GetItemText(hTemp);    if (! str.Find("Sam")) // 如果找到,就把他MsgBox出来    {     MessageBox(str);    }   }  }  hRoot = m_tc.GetNextItem(hRoot, TVGN_NEXT); } 


    最新回复(0)