如何获取在运行时创建的MFC中的Treeview(CTreeCtrl)的点击事件? [英] How to get Click Event of Treeview(CTreeCtrl) in MFC created at runtime?
问题描述
我在MFC应用程序的运行时创建了一个树视图,我已经添加了几个节点,现在我想做一些点击节点的东西,所以我可以得到树视图的点击事件?
I have created a treeview at runtime in MFC application , I have added few nodes to it now i want to do some stuff on click of nodes so how i can get click event of treeview ?
我的代码看起来像这样:
My code looks like this :
CTreeCtrl *m_ctlTreeview;
m_ctlTreeview = new CTreeCtrl ;
m_ctlTreeview->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |
TVS_TRACKSELECT,
CRect(25, 60, 385, 260), this, 0x1221);
hparentitem = m_ctlTreeview->InsertItem("Parent",TVI_ROOT);
m_ctlTreeview->InsertItem("Child", hparentitem);
推荐答案
一个选项是为通知消息添加处理程序在设计时使用消息映射中的 ON_NOTIFY
,为该子窗口ID(在您的示例中为0x1221)设置为父类。
One option is to add a handler for the notification messages for that child window ID (0x1221 in your example) to the parent class at design time using ON_NOTIFY
in the message map as usual. If there are no messages, the handler won't be triggered.
或者,您可以添加一个通用 WM_NOTIFY
处理程序到具有 ON_MESSAGE
的父窗口的消息映射,然后检查消息是否来自您的新树控件。
Alternatively, you could add a generic WM_NOTIFY
handler to the message map of the parent window with ON_MESSAGE
, and then check to see if the message comes from your new tree control.
这篇关于如何获取在运行时创建的MFC中的Treeview(CTreeCtrl)的点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!