要让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
-
zero The item has no child items.
one The item has one or more child items. //以上两个容易理解不再嗷述
I_CHILDRENCALLBACK //重点是这个
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就可以把+号按钮去掉了。