VC: CTreeCtrl

Source: Internet
Author: User

(Create an image linked list, load bitmap and add it to an image linked list, create a view control, set a view control image linked list, create a structure to insert a Tree View, set properties, and obtain the returned handle as a node) continue operation ...)

1. Basic Knowledge:

HICON hIcon [3];

Int n;

M_imagelist.Create (16, 16, 0, 8 );

// M_imagelist.Create (32, 32, 8 );

HIcon [0] = AfxGetApp ()-> LoadIcon (IDI_ICON1 );

HIcon [1] = AfxGetApp ()-> LoadIcon (IDI_ICON2 );

HIcon [2] = AfxGetApp ()-> LoadIcon (IDI_ICON3 );

HIcon [3] = AfxGetApp ()-> LoadIcon (IDI_ICON4 );

 

 

For (n = 0; n <4; n ++)

{

M_imagelist.Add (hIcon [n]);

}

CTreeCtrl * pTree = (CTreeCtrl *) GetDlgItem (IDC_TREE1 );

PTree-> SetImageList (& m_imagelist, TVSIL_NORMAL );

TV _INSERTSTRUCT tvinsert;

Tvinsert. hParent = NULL;

Tvinsert. hInsertAfter = TVI_LAST;

Tvinsert. item. mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;

 

// Tvinsert. item. hItem = NULL;

Tvinsert. item. hItem = TVI_ROOT;

Tvinsert. item. state = 0;

Tvinsert. item. stateMask = 0;

Tvinsert. item. cchTextMax = 6;

Tvinsert. item. iSelectedImage = 3;

Tvinsert. item. cChildren = 0;

Tvinsert. item. lParam = 0;

// The first layer

Tvinsert. item. pszText = "school ";

Tvinsert. item. iImage = 0;

HTREEITEM hDad = pTree-> InsertItem (& tvinsert );

// Layer 2

Tvinsert. hParent = hDad;

Tvinsert. item. pszText = "computer system ";

Tvinsert. item. iImage = 1;

HTREEITEM hDad21 = pTree-> InsertItem (& tvinsert );

Tvinsert. item. pszText = "management system ";

HTREEITEM hDad22 = pTree-> InsertItem (& tvinsert );

// Layer 3

// Two sub-projects of the first project at Layer 2

Tvinsert. hParent = hDad21;

Tvinsert. item. pszText = "network engineering ";

Tvinsert. item. iImage = 2;

HTREEITEM hDad211 = pTree-> InsertItem (& tvinsert );

Tvinsert. item. pszText = "Software Engineering ";

HTREEITEM hDad212 = pTree-> InsertItem (& tvinsert );

// Two subprojects of the second project at Layer 2

Tvinsert. hParent = hDad22;

Tvinsert. item. pszText = "e-commerce ";

Tvinsert. item. iImage = 2;

HTREEITEM hDad221 = pTree-> InsertItem (& tvinsert );

/*

CTreeCtrl * pCtrl = (CTreeCtrl *) GetDlgItem (IDC_TREE1 );

ASSERT (pCtrl! = NULL );

 

// Insert a root item using the structure. We must

// Initialize a TVINSERTSTRUCT structure and pass its

// Address to the call.

 

TVINSERTSTRUCT tvInsert;

TvInsert. hParent = NULL;

TvInsert. hInsertAfter = NULL;

TvInsert. item. mask = TVIF_TEXT;

TvInsert. item. pszText = _ T ("United States ");

 

HTREEITEM hCountry = pCtrl-> InsertItem (& tvInsert );

 

// Insert subitems of that root. Pennsylvania is

// A state in the United States, so its item will be a child

// Of the United States item. We won't set any image or states,

// So we supply only the TVIF_TEXT mask flag. This

// Override provides nearly complete control over

// Insertion operation without the tedium of initializing

// A structure. If you're going to add lots of items

// To a tree, you might prefer the structure override

// As it affords you a performance win by allowing you

// To initialize some fields of the structure only once,

// Outside of your insertion loop.

 

HTREEITEM hPA = pCtrl-> InsertItem (TVIF_TEXT,

_ T ("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL );

 

// Insert the "Washington" item and assure that it is

// Inserted after the "Pennsylvania" item. This override is

// More appropriate for conveniently inserting items

// Images.

 

HTREEITEM hWA = pCtrl-> InsertItem (_ T ("Washington "),

0, 0, hCountry, hPA );

 

// We'll add some cities under each of the states.

// The override used here is most appropriate

// For inserting text-only items.

 

PCtrl-> InsertItem (_ T ("pitt0000gh"), hPA, TVI_SORT );

PCtrl-> InsertItem (_ T ("Harrisburg"), hPA, TVI_SORT );

PCtrl-> InsertItem (_ T ("Altoona"), hPA, TVI_SORT );

 

PCtrl-> InsertItem (_ T ("Seattle"), hWA, TVI_SORT );

PCtrl-> InsertItem (_ T ("Kalaloch"), hWA, TVI_SORT );

PCtrl-> InsertItem (_ T ("Yakima"), hWA, TVI_SORT );

 

*/

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.