使用TREEVIEW,我如何知道我选择了哪个项目? [英] Using TREEVIEW, how do I know which item I selected?

查看:112
本文介绍了使用TREEVIEW,我如何知道我选择了哪个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TreeView列表:



root

| --aa

| --bb


当我点击某个项目显示消息aa被点击时,当我点击bb项目显示消息bb被cilcked时,我该怎么办?



只使用WINDOWS API没有MFC?



请帮帮我,这对我来说非常重要!!



我尝试过:



案例WM_NOTIFY:

如果(((LPNMHDR)lParam) - >代码== NM_LCLICK)//右键单击

{

Selected =(HTREEITEM)SendDlgItemMessage(hWndList,

IDC_TREE1,TVM_GETITEM,TVGN_TARET,0);

if(Selected == NULL)

{

MessageBox();

休息;

}



SendDlgItemMessage(hWndList,IDC_TREE1,

TVM_SELECTITEM,TVGN_CARET ,(LPARAM)精选);

}

休息;



这就是我所做的,但是我无法得到迭代的信息我点击了。

你能给我一些建议,代码会更好!谢谢!

TreeView list:

root
|--aa
|--bb

How can i do when i click aa item show message "aa was clicked",when i click bb item show message "bb was cilcked"?

Only using WINDOWS API No MFC?

please help me,this is really important to me!!

What I have tried:

case WM_NOTIFY:
if(((LPNMHDR)lParam)->code == NM_LCLICK) // Right Click
{
Selected=(HTREEITEM)SendDlgItemMessage (hWndList,
IDC_TREE1,TVM_GETITEM,TVGN_TARET,0);
if(Selected==NULL)
{
MessageBox();
break;
}

SendDlgItemMessage(hWndList,IDC_TREE1,
TVM_SELECTITEM,TVGN_CARET,(LPARAM)Selected);
}
break;

this is what i did,but i can't get the infomation of the item i clicked.
can you give me some advise,codes will be better!thank you!

推荐答案

你做错了。您没有传递指向 LVITEM 结构的指针,该结构是接收项目信息所必需的。相反,你转换函数结果,它只返回TRUE或FALSE,表示成功或失败,但从不指示你错误假设的指针。



请参阅:

LVM_GETITEM消息(Windows) [ ^ ],

https://msdn.microsoft.com/en-us/library/windows/desktop/bb774760(v = vs.85).aspx [ ^ ]。



此外,我不确定你是否正确使用 SendDlgItemMessage ;您可以选择此功能或 SendMessage 。这在此解释: https://support.microsoft.com/en-us/kb/12273 [ ^ ]。



或者,您可以使用宏 ListView_GetItem

ListView_GetItem宏(Windows) [ ^ ]。



-SA
You are doing it wrong. You don't pass a pointer to LVITEM structure which is needed to receive the information on the item. Instead, you cast the function result, which merely returns TRUE or FALSE, indicating success or failure, but never a pointer as you incorrectly assumed.

Please see:
LVM_GETITEM message (Windows)[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774760(v=vs.85).aspx[^].

Besides, I'm not sure you correctly use SendDlgItemMessage; you can choose between this function or SendMessage. This is explained here: https://support.microsoft.com/en-us/kb/12273[^].

Alternatively, you can use the macro ListView_GetItem:
ListView_GetItem macro (Windows)[^].

—SA


这篇关于使用TREEVIEW,我如何知道我选择了哪个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆