码迷,mamicode.com
首页 > 其他好文 > 详细

学习:Tree Control

时间:2020-02-08 13:42:47      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:修改   str   git   change   cst   src   alt   com   学习   

/*
D:\Visual_Studio_repos\MFC\7*/

/*插入*/
void CMy7Dlg::OnBnClickedButton1()
{
    /*
        逻辑顺序:
        1、利用GetSelectedItem函数获取被选中的节点
        2、if判断是否有节点选中,如果没有的话创建一个HTREEITEM结构体作为节点进行插入
        3、插入的顺序为 hInsertAfter = TVI_LAST,节点的名称为EDIT控件的名称
        4、进行插入InsertItem 返回一个新节点的句柄
        5、插入成功后,默认选中插入的节点
    */
    CString mString;
    GetDlgItemText(IDC_EDIT1,mString);
    HTREEITEM hTree = m_tree_1.GetSelectedItem();
    if (hTree == NULL) {
        hTree = TVI_ROOT;
    }

    TVINSERTSTRUCT tv = { 0 };
    tv.hParent = hTree;
    tv.hInsertAfter = TVI_LAST;
    tv.item.pszText = mString.GetBuffer(); //获取Cstring的字符串的指针
    tv.item.mask = TVIF_TEXT;
    HTREEITEM NewTree = m_tree_1.InsertItem(&tv); // 插入节点
    m_tree_1.SelectItem(NewTree); //插入后 再进行默认选中
}


/*修改*/
void CMy7Dlg::OnBnClickedButton2()
{
    CString mString;
    CString TreeName;
    GetDlgItemText(IDC_EDIT1, mString);
    HTREEITEM hTree = m_tree_1.GetSelectedItem();
    m_tree_1.SetItemText(hTree, mString.GetBuffer());

}


void CMy7Dlg::OnBnClickedButton3()
{
    HTREEITEM hTree = m_tree_1.GetSelectedItem();
    m_tree_1.DeleteItem(hTree);
}

/*实时EDIT节点名*/
void CMy7Dlg::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
    
    CString mString;
    HTREEITEM hTree = m_tree_1.GetSelectedItem();
    mString = m_tree_1.GetItemText(hTree);
    SetDlgItemText(IDC_EDIT1, mString);
    *pResult = 0;
}

技术图片

学习:Tree Control

标签:修改   str   git   change   cst   src   alt   com   学习   

原文地址:https://www.cnblogs.com/zpchcbd/p/12275866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!