1026 A tree control sends a TVN_ITEMEXPANDING notification message
Tree Control Parent and Child Items
Any item in a tree control (CTreeCtrl) can have a list of subitems, which are called child items, associated with it. An item that has one or more child items is called a parent item. A child item is displayed below its parent item and is indented to indicate it is subordinate to the parent. An item that has no parent is at the top of the hierarchy and is called a root item.
At any given time, the state of a parent item's list of child items can be either expanded or collapsed. When the state is expanded, the child items are displayed below the parent item. When it is collapsed, the child items are not displayed. The list automatically toggles between the expanded and collapsed states when the user double-clicks the parent item or, if the parent has the TVS_HASBUTTONS style, when the user clicks the button associated with the parent item. An application can expand or collapse the child items by using the Expand member function. 展开/合起 之间的切换。
You add an item to a tree control by calling the InsertItem member function. This function returns a handle of the HTREEITEM type, which uniquely identifies the item. When adding an item, you must specify the handle of the new item's parent item. If you specify NULL or the TVI_ROOT value instead of a parent item handle in the TVINSERTSTRUCT structure or hParent parameter, the item is added as a root item. 加入一个子项。
A tree control sends a TVN_ITEMEXPANDING notification message when a parent item's list of child items is about to be expanded or collapsed. The notification gives you the opportunity to prevent the change 明明白白真真切切,可以在收到这个消息时阻止原有的展开/合起,目前可以猜想:鼠标双击TreeItem的时候,双击事件先被控件接受并处理,先进行了展开,之后才给其父亲Dlg发通知消息。or to set any attributes of the parent item that depend on the state of the list of child items. After changing the state of the list, the tree control sends a TVN_ITEMEXPANDED notification message.
先实践一下,使用wizard添加一个OnItemexpandingTreeSmblist函数,
自动添加了如下代码:
1,函数声名 afx_msg void OnItemexpandingTreeSmblist(NMHDR* pNMHDR, LRESULT* pResult);
2,消息映射
BEGIN_MESSAGE_MAP(CDlgSmbList, CDialog)
//{{AFX_MSG_MAP(CDlgSmbList)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
ON_NOTIFY(IPN_FIELDCHANGED, IDC_IPADDRESS1, OnFieldchangedIpaddress1)
ON_NOTIFY(IPN_FIELDCHANGED, IDC_IPADDRESS2, OnFieldchangedIpaddress2)
ON_NOTIFY(NM_DBLCLK, IDC_TREE_SMBLIST, OnDblclkTreeSmblist)
ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_SMBLIST, OnItemexpandingTreeSmblist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3 函数定义void CDlgSmbList::OnItemexpandingTreeSmblist(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
经过实验,果然如上面的猜想,虽然OnItemexpandingTreeSmblist为空,但是expand/collapse依然完成无误,控件的通知消息到控件发出这个消息时再处理已经晚了,虽然可以把它再打回去,但这个方案显然太不完美。
问题:控件的消息究竟是怎么传递的,CTreeCtrl控件处理expand/collapse逻辑的实现证据在哪儿?