First school MFC (3) - one of tree controls

zhaozj2021-02-16  61

First school MFC (3) - one of tree controls

When studying a tree control, first I have to build it. To this end, I use the following steps:

1: I have established a based dialog application. On the dialog box, place a tree.

2: Add a ctreectrl object M-WNDTREE in the dialog class

3: Add the following code in the OnInitDialog function of the dialog:

HtreeItem Hitem1a = m_wndtree.insertitem (_T ("layer1_a"), 0, 1);

M_Wndtree.InsertItem (_T ("Layer2_1a"), 0, 1, Hitem1a, TVi_Last);

HtreeItem Hitem2_1b = m_wndtree.insertitem (_t ("layer2_1b"), 0, 1, hitem1a, TVi_last);

M_Wndtree.InsertItem (_t ("Layer3_1a"), 0, 1, HITEM2_1B);

M_Wndtree.InsertItem (_t ("layer3_1b"), 0, 1, hitem2_1b);

M_Wndtree.InsertItem (_t ("layer3_1c"), 0, 1, hitem2_1b;

M_Wndtree.Insertitem (_t ("layer2_1c"), 0, 1, hitem1a, TVi_last);

HTREEITEM HITEM1B = m_wndtree.insertitem (_t ("layer1_b"), 0, 1);

m_wndtree.insertitem (_T ("Layer2_2a"), 0, 1, Hitem1b, TVi_Last);

M_Wndtree.Insertitem (_t ("Layer2_2B"), 0, 1, Hitem1b, TVi_Last);

M_Wndtree.Insertitem (_T ("Layer2_2C"), 0, 1, Hitem1b, TVi_Last);

(Note: The above code is my Copy, I want to thank this friend)

4: Compile operation, a tree is displayed on the dialog.

5: After the tree comes out, I also want to add an icon in front:

First, define a cimagelist object M-IMGLST in the dialog class

Second, in front of the above code, add the following code:

m_imglst.create (idb_tree, 16, 1, rgb (0,255,255));

M_Wndtree.setimageList (& m_imglst, tvsil_normal);

The icon is displayed; the creation of the tree is completed.

转载请注明原文地址:https://www.9cbs.com/read-25250.html

New Post(0)