获取树状视图中的选定项目 [英] Get selected item in treeview
本文介绍了获取树状视图中的选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用WinApi函数用C ++编写的程序(我没有使用MFC).在此程序中,我有一个树状视图(可以添加或删除元素),并且我想解决一个问题:我想确切地知道选择了哪个项目.请帮忙.
示例:
I have a program written in C++ with WinApi functions (I am not using MFC). In this program I have a treeview (elements can be added or deleted) and I want to solve a problem: I want to know exactly which item was selected. Please help.
Example:
+Color
-Red
-Blue
+Ground
-sldfs
-sdfsdfafsd
返回值:红色(或其他颜色)
Return: Color red (or something else)
推荐答案
类似这样的东西
Something like this
// Get a handle to the selected item
HTREEITEM hSelectedItem = TreeView_GetSelection(hwnd);
if (hSelectedItem == NULL) // Nothing selected
return;
// Now get the text of the selected item
TCHAR buffer[128];
TVITEM item;
item.hItem = hSelectedItem;
item.mask = TVIF_TEXT;
item.cchTextMax = 128;
item.pszText = buffer;
if (TreeView_GetItem(hwnd, &item))
{
cout << item.pszText << " is selected" << endl;
}
您最好看看控制文档[
You would better take a look to control documentation [^].
感谢您的回答.他们对我很有帮助.
Thanks for the ansver. They are very helped me.
这篇关于获取树状视图中的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文