在MFC中使用TreeView进行事件管理的问题 [英] Problem with event management with TreeView in MFC
问题描述
我在MFC中有一个TreeView控件.
我所做的是,我以某种方式将某些元素放入该树中,使得depth0元素是字母,而深度一个元素是数字,如下所示:-
|
MyTree
| A
| | --1
| | --2
| | --3
|
| --- B
| | --4
| | --5
| | --6
|
| --- C
| | --7
| | --8
| | --9
现在,我想,当我双击字母时,它会显示消息,选择该字母,如果我双击数字,它会显示消息,则选择该数字.
我什至不知道如何在其项目上实现双击事件.如何在...中实现整个过程.
I have a TreeView Control in MFC.
what i did is, i put some elements in a way into that tree such that, the depth0 elements are alphabets and the depth one elements are numbers as below:-
|
MyTree
| A
| |--1
| |--2
| |--3
|
|---B
| |--4
| |--5
| |--6
|
|---C
| |--7
| |--8
| |--9
Now, i want, when i double click the alphabets, it displays message, that alphabet is chosen, and if i double click numbers, it displays message, that number is chosen.
I even dont know, how to implement the double click event on its items. How to implement this whole thing in..??
推荐答案
您需要处理TVN_SELCHANGING
和TVN_SELCHANGED
通知消息.项目选择的解释如下:
http://msdn.microsoft.com/en-us/library/a9a9f1t7%28v = vs.100%29.aspx [ ^ ].
此处的示例显示如何获取当前选定的项目:
http://www.codersource.net/MFC/MFCTutorials/MFCTreeusageandexample.aspx [ ^ ].
基本上,这就是您所需要的.现在,当您知道要查找的内容(用于Web搜索的关键字)时,可以尝试查找一些更详细的代码示例.
祝你好运,
—SA
You need to handleTVN_SELCHANGING
andTVN_SELCHANGED
notification messages. Item selection is explained here:
http://msdn.microsoft.com/en-us/library/a9a9f1t7%28v=vs.100%29.aspx[^].
The example here shows how you get the currently selected item:
http://www.codersource.net/MFC/MFCTutorials/MFCTreeusageandexample.aspx[^].
Basically, that''s all you need. Now when you know what to look for (keywords for Web search), you can try to find some more detailed code samples.
Good luck,
—SA
SAKryukov给了您一些非常重要的信息,我想在此添加一些信息:
您可以处理WM_NOTIFY Windows消息和NM_CLICK操作,可以获得正确的树对象
这是一个简单的示例:
SAKryukov gave you some very important information, I want to add some with this:
You can Process WM_NOTIFY windows message and NM_CLICK action, you can get the proper Tree Object
here is a simple example:
case WM_NOTIFY:
NMHDR *nmhdr;
nmhdr=(NMHDR *)lParam;
switch(nmhdr->code)
{
case NM_CLICK:
TVHITTESTINFO tv;
HTREEITEM htr,htr_tblName;
RECT rc_tree;
POINT ms_pt;
GetCursorPos(&ms_pt);
GetWindowRect(nmhdr->hwndFrom, &rc_tree);
tv.pt.x=ms_pt.x-rc_tree.left;
tv.pt.y=ms_pt.y-rc_tree.top;
htr=TreeView_HitTest(nmhdr->hwndFrom,&tv); //here is the object of the leaf that got clicked
}
祝你好运
good luck
这篇关于在MFC中使用TreeView进行事件管理的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!