1025
屏蔽掉CTreeCtrl双击事件的原有逻辑,加上自己的逻辑,做到了这个功能,MFC的消息机制才算是有了理解。
尝试对CTreeCtrl::Expand函数进行跟踪,断点没有停住。继续看看msdn关于CTreeCtrl的描述。
Typical usage of a tree control (CTreeCtrl) follows the pattern below:
The control is created. If the control is specified in a dialog box template or if you're using CTreeView, creation is automatic when the dialog box or view is created. If you want to create the tree control as a child window of some other window, use the Create member function. 目前是使用对话框模板进行创建的。
If you want your tree control to use images, set an image list by calling SetImageList. You can also change the indentation by calling SetIndent. A good time to do this is in OnInitDialog (for controls in dialog boxes) or OnInitialUpdate (for views). 使用图片就不看了。
Put data into the control by calling the CTreeCtrl's InsertItem function once for each data item. InsertItem returns a handle to the item you can use to refer to it later, such as when adding child items. A good time to initialize the data is in OnInitDialog (对话框的初始化for controls in dialog boxes) or OnInitialUpdate (for views).
目前使用了HTREEITEM hItemDir = pTree->InsertItem(FindFileData.cFileName, 0, 1, hItemParent, TVI_LAST);进行树项目的添加。
As the user interacts with the control, it will send various notification messages通知消息是怎样的使用方法呢?对话框中的消息大量集中在控件,想熟练使用对话框,控件消息的道理跳不过去. You can specify a function to handle each of the messages you want to handle by adding an ON_NOTIFY_REFLECT macro in your control window's message map or by adding an ON_NOTIFY macro to your parent window's message map.
重点看一下这段话。处理控件通知消息的两种方法:1,加ON_NOTIFY_REFLECT宏到控件的消息映射集,或者2,加ON_NOTIFY宏到其父亲窗口(主要考虑对话框)的消息映射集。
搜索当前项目:
使用wizard生成的MESSAGE_MAP,双击CTreeCtrl的语句。
ON_NOTIFY(NM_DBLCLK, IDC_TREE_SMBLIST, OnDblclkTreeSmblist)
#define ON_NOTIFY(wNotifyCode, id, memberFxn)
{
WM_NOTIFY, (WORD)(int)wNotifyCode, (WORD)id, (WORD)id, AfxSig_vNMHDRpl, (AFX_PMSG)(void (AFX_MSG_CALL CCmdTarget::*)(NMHDR*, LRESULT*))&memberFxn
},
另外一个加在CSheetTabCtrl控件的MESSAGE_MAP中。分别对应msdn的描述。
BEGIN_MESSAGE_MAP(CSheetTabCtrl, CTabCtrl)
//{{AFX_MSG_MAP(CSheetTabCtrl)
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Call the various Set member functions to set values for the control. Changes that you can make include setting the indentation and changing the text, image, or data associated with an item.
Use the various Get functions to examine the contents of the control. You can also traverse the contents of the tree control with functions that allow you to retrieve handles to parents, children, and siblings of a specified item. You can even sort the children of a particular node.
When you're done with the control, make sure it's properly destroyed. If the tree control is in a dialog box or if it's a view, it and the CTreeCtrl object will be destroyed automatically在对话框中的CTreeCtrl会自动销毁. If not, you need to ensure that both the control and the CTreeCtrl object are properly destroyed.
问题还是没解决,新添加的处理Notify消息的函数几乎为空:
void CDlgSmbList::OnDblclkTreeSmblist(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
那么是什么逻辑使Item展开/合起 了呢??