Use the Treeview control in the SDK

Source: Internet
Author: User

Using controls in the SDK is very troublesome. Unlike editing tools such as VB, you can easily control controls by directly setting control properties. The most commonly used controls include buttons, ListBox, ComboBox, edit, and image list. after learning the SDK for more than a month, I found that only buttons and edit controls are used, other controls are not used at all, so I decided to take some time to familiarize myself with these commonly used controls. The first thing I should be familiar with is the Treeview control.

I. Treeview

Whether it is a Treeview control or a listview control, several structs are used. If you do not know these structs, you will be confused when using the control and modify the struct values randomly, I don't know where to set the desired results, but I don't know how to change the results. I don't know why, the status is very good tonight, and my mind is very quiet. When I was familiar with the control a few days ago, I copied the Code directly from msdn, and I didn't have the mind to read the code, after half a day, the desired results are not displayed. If there is a correct saying, the mentality determines success or failure.

Using the Treeview control will use two struct types: tvitem and tvinsertstruct. If you are familiar with these two struct types, it is basically no problem to control the Treeview.

1. tvitem struct

This struct is used to set node information, such as the node name, the length occupied by the node name, the specified struct members that can be used, and the node status. Let's take a look at the definition of the tvitem struct:

Typedef struct tagtvitem {
Uint mask;
Htreeitem hitem;
Uint state;
Uint statemask;
Lptstr psztext;
Int cchtextmax;
Int iimage;
Int iselectedimage;
Int cChildren;
Lparam;
} Tvitem, * lptvitem;

Mask

Is a struct member that can be used. For example, if you set the value of mask to "tvif_text | tvif_state", you can only use psztext and State members in the tvitem struct. Of course, mask members are available at any time.

Hitem

After selecting the handle of the node, it takes only half a day to understand the role of the Member. Since it is a handle, you must first obtain the handle before using the handle. When creating the first node in the Treeview, you do not need to set this member. With the first node, you can obtain the node handle in multiple ways, such as the treeview_insertitem function, treeview_getnextitem function, and treeview_getparnt function, after obtaining the node handle, you can control the node.

State

This is used to set the node status. The setting of this Member seems complicated. The number of statuses of a node is unknown. It seems that there may be about 16 states. After a good research, we found that the State member is of the uint type, that is, the unsigned int data type, which is 16 bits. That is to say, each bit is of a State, and there are exactly 16 states. 0-7 digits are the state of normal nodes, while 8-11 digits cover image indexes? I don't understand it! The 12-15 digits are image indexes. I estimate that 8-11 and 12-15 are several statuses of node images, and the operations are turned around and turned back. It is better to understand the status of nodes ranging from 0 to 7, as shown below:

Tvis_bold-bold node name

Tvis_cut-use the selected node as the target for copying and pasting

Tvis_drophilited-drag the selected node as the drag target and use it to drag

Tvis_expanded-expand the subnode under this node

Tvis_expandedonce-do not understand ??????

Tvis_expandpartial-expand some nodes

Tvis_selected-the node is selected

Three more

Tvis_overlaymask-mask covering image indexes, not quite familiar

Tvis_stateimagemask-image index mask, not quite familiar

Tvis_usermask-same as tvis_stateimagemask

How can there be only 10 States and 6 in this number?

Statemask

Statemask is used to specify valid node states, similar to mask. To use tvis_bold and tvis_expanded states, you must specify these two states in statemask, that is to say, the State and statemask are set the same.

Psztext

Node name.

Cchtextmax

Node name length.

Iimage

The image index of a node in an unselected state, as if to use imagelist to create an image index.

Iselectedimage

Image indexes of nodes in the selected status

Indicates whether the tree control item has a flag of the relevant subnode. This member can be one of the following values:
0 -- indicates that this item has no subnodes.
1 -- indicates that this item has one or more subnodes.
I _childrencallback -- the parent window will always track and determine whether this item has child nodes. In this case, if the fruit tree control needs to display items, it will send a tvn_getdispinfo notification message to the parent window to determine whether this item has child nodes. If the fruit tree control contains the tvs_hasbuttons style, it uses this member to determine whether to display the button to indicate that a subnode exists. You can also use this member to force the tree control display button, although no subnode is inserted under this item. In this way, the Control Memory occupied by the subnode is inserted under this item to be minimized.

Lparam

32-bit values related to the control. What is the value? Don't know

Although the tvitem structure is not clear yet, there should be no problems with General node control.

2. tvinsertstruct struct

The tvitem struct is used to set individual and independent node information, while the tvinsertstruct is used to set all attributes of the node to be added, including the tvitem struct, for example, if the node is added to the Treeview and the parent node handle, the following is the structure definition:

Typedef struct tagtvinsertstruct {
Htreeitem hparent;
Htreeitem hinsertafter;
# If (_ win32_ie> = 0x0400)
Union
{
Tvitemex itemex;
Tvitem item;
} Dummyunionname;
# Else
Tvitem item;
# Endif
} Tvinsertstruct, * lptvinsertstruct;
A total of four members

Hparent

Parent node handle

Hinsertafter

Before which node to insert

Item

A tvitem struct

In addition to the role of a few members in tvitem, the above two struct structures are still unclear.

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.