让 CtreeCtrl 的节点在没有子节点的情况下显示+号按钮

要让CtreeCtrl 的节点在没有子节点的情况下显示+号按钮,可以在 InsertItem 的时候设置 item 的 cChildren 属性为1 。下面是 MSDN 的对 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

member: cChildren

Flag that indicates whether the item has associated child items. This member can be one of the following values.
zero The item has no child items. one  The item has one or more child items. //以上两个容易理解不再嗷述   I_CHILDRENCALLBACK   //重点是这个
The 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.

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.

另外,捕获 TVN_ITEMEXPANDING 通知,在里面用 GetChildItem 判断要展开的节点是否有子节点(不能用 ItemHasChildren,因为它就是用 cChildren 来判断是否有子节点的),如果没有子节点就把 cChildren 设置为0就可以把+号按钮去掉了。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值