CTreeCtrl第三课

来源:互联网 发布:知乎北京酒店 编辑:程序博客网 时间:2024/04/30 18:21

  昨天对CTreeCtrl的TVITEM进行学习时,没有完,现在开始吧。TVITEMEX比TVITEM多的最后一个成员在昨天已经学习了,就是用来设置项高的。对于其他的两个结构是相同的了。那下面就学习一下TVITEM结构吧。该结构如下:

typedef struct tagTVITEM{
    UINT      mask;
    HTREEITEM hItem;
    UINT      state;
    UINT      stateMask;
    LPTSTR    pszText;
    int       cchTextMax;
    int       iImage;
    int       iSelectedImage;
    int       cChildren;
    LPARAM    lParam;
} TVITEM, FAR *LPTVITEM;

下面是MSDN上的解释,试着翻译当学习了。

Members

mask
Array of flags that indicate which of the other structure members contain valid data. When this structure is used with the TVM_GETITEM message, the mask member indicates the item attributes to retrieve. This member can be one or more of the following values.
mask标志数组指出了结构中另外的那些成员包含了有效的数据。该结构被使用在TVM_GETITEM消息时,mask标志指出了返回项的属性,这个成员能够使用下面一个或多个值的组合。
TVIF_CHILDRENThe cChildren member is valid.子成员是有效的TVIF_DI_SETITEM

The tree view control will retain the supplied information and will not request it again. This flag is valid only when processing the TVN_GETDISPINFO notification.

树形控件将保持已提供的信息,而不再重新请求。仅仅只有在处理TVN_GETDISPINFO通知消息的时候该标志是有效的。

TVIF_HANDLEThe hItem member is valid.hItem成员是有效的TVIF_IMAGEThe iImage member is valid.iImage成员是有效的TVIF_PARAMThe lParam member is valid.lParam成员是有效的TVIF_SELECTEDIMAGEThe iSelectedImage member is valid.iSelectedImage成员是有效的TVIF_STATEThe state and stateMask members are valid.state和stateMask成员是有效的TVIF_TEXT

The pszText and cchTextMax members are valid.pszText和cchTextMax成员是有效的

 

hItem
Item to which this structure refers. 结构相关项,也就是当前处理的项
state
Set of bit flags and image list indexes that indicate the item's state. When setting the state of an item, the stateMask member indicates the bits of this member that are valid. When retrieving the state of an item, this member returns the current state for the bits indicated in the stateMask member.

Bits 0 through 7 of this member contain the item state flags. For a list of possible item state flags, see Tree View Control Item States.

The overlay image is superimposed over the item's icon image. Bits 8 through 11 of this member specify the one-based overlay image index. If these bits are zero, the item has no overlay image. To isolate these bits, use the TVIS_OVERLAYMASK mask. To set the overlay image index in this member, use the INDEXTOOVERLAYMASK macro. The image list's overlay images are set with the ImageList_SetOverlayImage function.

A state image is displayed next to an item's icon to indicate an application-defined state. Specify the state image list by sending a TVM_SETIMAGELIST message. To set an item's state image, include the TVIS_STATEIMAGEMASK value in the stateMask member of the TVITEM structure. Bits 12 through 15 of the structure's state member specify the index in the state image list of the image to be drawn.

To set the state image index, use INDEXTOSTATEIMAGEMASK. This macro takes an index and sets bits 12 through 15 appropriately. To indicate that the item has no state image, set the index to zero. This convention means that image zero in the state image list cannot be used as a state image. To isolate bits 12 through 15 of the state member, use the TVIS_STATEIMAGEMASK mask.

位标记和图像列表索引的设置,指出项的状态。当设置了一个项的状态,stateMask成员指出这个成员的位是有效的。当取加一个项的状态时,这个成员返回stateMask成员指出的位的当前状态。
这个成员的0至7位包含了项的状态标记。关于可能的项状态标记,参见Tree View Control Item States.

覆盖图像覆盖在项的图标图像之上。这个成员的8至11位指定了以1为基准的覆盖图像索引。如果这些位是0,这个项没有覆盖图像。要隔离这些位,使用TVIS_OVERLAYMASK掩码。要在这个成员中设置覆盖图像索引,使用INDEXTOOVERLAYMASK宏。图像列表的覆盖图像是被ImageList_SetOverlayImage函数设置的。

一个状态图像是仅次于指出应用程序定义的状态的项的图标显示的。通过发送TVM_SETIMAGELIST消息来指定一个状态图像列表。要设置一个项的状态图像,在TVITEM结构的stateMask成员中包含TVIS_STATEIMAGEMASK值。结构的state成员的12至15位指定状态图像列表中被绘制图像的索引。

要设置状态图像索引,使用INDEXTOSTATEIMAGEMASK。这个宏把一个索引适当的设置到12至15位上。要指出项没有状态图像,设置索引为0。这意味着在状态图像列表中的图像0不能被作为一个状态图像使用。要隔离state成员的位12至15,使用TVIS_STATEIMAGEMASK掩码。

stateMask
Bits of the state member that are valid. If you are retrieving an item's state, set the bits of the stateMask member to indicate the bits to be returned in the state member. If you are setting an item's state, set the bits of the stateMask member to indicate the bits of the state member that you want to set. To set or retrieve an item's overlay image index, set the TVIS_OVERLAYMASK bits. To set or retrieve an item's state image index, set the TVIS_STATEIMAGEMASK bits.
state成员的位是有效的。如果你取回了一个项的状态,设置stateMask成员的位来指出state成员中的这个位被返回。如果你设置了一个项的状态,设置stateMask成员的位来指出state成员的这个位是你想设置的。要设置或取回一个项的覆盖图像的索引,设置TVIS_OVERLAYMASK位。要设置和取回一个项的状态图像索引,设置TVIS_STATEIMAGEMASK位。
pszText
Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is the LPSTR_TEXTCALLBACK value, the parent window is responsible for storing the name. In this case, the tree view control sends the parent window a TVN_GETDISPINFO notification message when it needs the item text for displaying, sorting, or editing and a TVN_SETDISPINFO notification message when the item text changes.

If the structure is receiving item attributes, this member is the address of the buffer that receives the item text.

如果这个结构指定了项属性,那么这个成员是指向一个以空字符结束的字符串,包含有项的文本。如果这个成员是值LPSTR_TEXTCALLBACK,那么父窗口为保存名字负责。既然这样,当树形视控件需要显示、保存或编辑项文本时,向父窗口发送TVN_GETDISPINFO通过消息,当项文本改变时,发送TVN_SETDISPINFO通知消息。

如果结构是取回项的属性,这个成员是取回项文本缓冲的地址。

cchTextMax
Size of the buffer pointed to by the pszText member, in characters. If this structure is being used to set item attributes, this member is ignored.
pszText成员指定缓冲的大小,以字符为单位。如果这个结构被使用来设置项属性,这个成员被忽略。
iImage
Index in the tree view control's image list of the icon image to use when the item is in the nonselected state.

If this member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree view control sends the parent a TVN_GETDISPINFO notification message to get the index when it needs to display the image.

当项是在非选择状态中时,是树形控件的图像列表的索引。

如果这个成员是值I_IMAGECALLBACK,父窗口为保存索引负责。既然这样,当树形视控件需要显示这个图像时,向父窗口发送TVN_GETDISPINFO通知消息来获得索引。

iSelectedImage
Index in the tree view control's image list of the icon image to use when the item is in the selected state.

If this member is the I_IMAGECALLBACK value, the parent window is responsible for storing the index. In this case, the tree view control sends the parent a TVN_GETDISPINFO notification message to get the index when it needs to display the image.

当项被选择时,是树形控件图像列表的索引。

如果这个成员是值I_IMAGECALLBACK,父窗口为保存索引负责。既然这样,当树形视控件需要显示这个图像时,向父窗口发送TVN_GETDISPINFO通知消息来获得索引

cChildren
Flag that indicates whether the item has associated child items. This member can be one of the following values. zeroThe item has no child items.没有子项oneThe item has one or more child items.有一个或更多子项I_CHILDRENCALLBACKThe parent window keeps track of whether the item has child items. In this case, when the tree view control needs to display the item, the control sends the parent a TVN_GETDISPINFO notification message to determine whether the item has child items. 对该项是否有子项父窗口进行跟踪,在这种情况下,当树形控件需要显示一个项时,树形控件发送给父窗口一个TVN_GETDISPINFO通知消息,目的是检测该项是否有子项。

If the tree view control has the TVS_HASBUTTONS style, it uses this member to determine whether to display the button indicating the presence of child items. You can use this member to force the control to display the button even though the item does not have any child items inserted. This allows you to display the button while minimizing the control's memory usage by inserting child items only when the item is visible or expanded.如果树形控件有TVS_HASBUTTONS风格,它使用这个成员检测当前子项是否显示了按钮,你能够使用该成员目的是强制显示按钮,即使该项没有任何子项被插入。允许你显示按钮当最少使用控件内存的的情况下。通过插入子项仅仅当项是可视的或展开的

lParam
32-bit value to associate with the item. 与项相关的32位值。

太多啦翻译的很乱。因为在翻译时感觉到很多东西都不能够理解其具体用法,就是没有劲啊。还是直接使用测试方便些,以后使用中在继续体会吧。在这主要知道该项有那么多个成员,这些成员中都涉及到些什么,具体的每个成员是干什么的,怎么用,只有是使用多了才会慢慢了解了。看这个也是很糊涂呢。写下这些,主要是混过眼熟吧,慢慢了,心急吃不了热豆腐喽。

原创粉丝点击