MFC Getting Started Sample tree control (Ctreecontrol)

Source: Internet
Author: User

1 //Add button2 voidCmfcapplication8dlg::onbnclickedbuttonadd ()3 {4     //adding nodes to the tree5 CString StrText;6 GetDlgItemText (idc_edit1, strText);7     if(strtext.getlength () = =0) {8AfxMessageBox (TEXT ("Please enter text"));9         return;Ten     } OneHtreeitem HItem = M_tree. GetSelectedItem ();//gets the currently selected node A     if(HItem = =NULL) -HItem =Tvi_root; -      theTvinsertstruct ts = {0 }; -Ts.hparent =HItem; -Ts.hinsertafter =Tvi_last; -Ts.item.pszText =Strtext.getbuffer (); +Ts.item.mask =Tvif_text; -Htreeitem Hnewitem = M_tree. InsertItem (&ts); +M_tree. SelectItem (Hnewitem);//Select the newly joined node AM_tree. EnsureVisible (Hnewitem);//The tree is too thought highly to see. at } -  - //Delete button - voidCmfcapplication8dlg::onbnclickedbuttondel () - { -     //gets the currently selected node inHtreeitem HItem = M_tree. GetSelectedItem ();//gets the currently selected node -     if(HItem = =NULL) { toAfxMessageBox (TEXT ("Please select a node")); +         return; -     } theHtreeitem hparent =M_tree. GetParentItem (HItem); * M_tree. DeleteItem (HItem); $ M_tree. SelectItem (hparent);Panax Notoginseng } -  the //Modify Button + voidcmfcapplication8dlg::onbnclickedbuttonupdate () A { the     //gets the currently selected node +Htreeitem HItem = M_tree. GetSelectedItem ();//gets the currently selected node -     if(HItem = =NULL) { $AfxMessageBox (TEXT ("Please select a node")); $         return; -     } - CString StrText; the GetDlgItemText (idc_edit1, strText); -     if(strtext.getlength () = =0) {WuyiAfxMessageBox (TEXT ("Please enter text")); the         return; -     } Wu M_tree. Setitemtext (HItem, strText); - } About  $ //Select New Node event - voidCmfcapplication8dlg::ontvnselchangedtree1 (NMHDR *pnmhdr, LRESULT *PResult) - { -Lpnmtreeview Pnmtreeview = reinterpret_cast<lpnmtreeview>(PNMHDR); A     //gets the currently selected node +Htreeitem HItem = M_tree. GetSelectedItem ();//gets the currently selected node the     if(HItem! =NULL) { -CString StrText =M_tree. GetItemText (HItem); $Setdlgitemtext (Idc_edit1, StrText);//Select the node text to add to the edit box the     } the  the*presult =0; the}

MFC Getting Started Sample tree control (Ctreecontrol)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.