MFC Controls: Tree controls (CTreeCtrl)

Source: Internet
Author: User

Tree-shaped control partitioning:

Root node: All nodes that have been shrunk

Node: able to expand

Leaf: Cannot unfold

Note: Nodes and leaves are not absolute divisions, and when a new subordinate is added to a leaf, the leaf becomes a node

The tree controls are added:

node struct: htreeitem, declaring the node variable with the struct body

To add an item to a control:

htreeitem InsertItem (lpctstr lpszitem,            //Item name int nImage,  // Index of the image of an item in the tree view Control image list int nselectedimage,  //tree view Control the index of the selected image of an item in the image list Htreeitem hparent = tvi_ ROOT,  //Insert The handle of the item to be inserted before the parent's handle//new item );
Note: Before adding an item, set the root node before initializing the

Tree control Mouse click:

  Determine the mouse position

Htreeitem Cmytreedlg::getselecttree () {    CPoint pt;    GetCursorPos (&pt); // get the current mouse position    M_mytree.screentoclient (&PT); // Convert screen coordinates to client area coordinates    Htreeitem Tree_item = M_mytree.hittest (PT); // call HitTest to find the tree node    corresponding to the click return Tree_item;//return mouse position node}

Get an item of text

CString GetItemText (Htreeitem hItem) const;

Gets the specified relationship item

Htreeitem GetNextItem (Htreeitem hItem, UINT nCode) const;

  nCodeThe flag can be one of the following values: TVGN_CARET retrieves the currently selected item . TVGN_CHILDretrieves the first subproject parameter by the specified item hItem . Retrieves the item that is the TVGN_DROPHILITE target of a drag-and-drop operation . TVGN_FIRSTVISIBLEretrieves the first visible item . TVGN_LASTVISIBLEretrieves the last expanded item in the tree. This does not retrieve the last item visible in the tree view window . TVGN_NEXTretrieves the next sibling . TVGN_NEXTVISIBLEretrieves the next visible item that follows the specified item . TVGN_PARENTretrieves the parent of the specified item . TVGN_PREVIOUSretrieves the preceding sibling . TVGN_PREVIOUSVISIBLEretrieves the first visible item that is located in the specified item. TVGN_ROOTretrieves the first child item of a root item that is part of a specified item.

Gets the parent of the specified item

Htreeitem GetParentItem (Htreeitem hItem) const;

MFC Controls: Tree controls (CTreeCtrl)

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.