How to use 'SetItemData()' and 'GetItemData()'?
来源:互联网 发布:java 通讯协议 编辑:程序博客网 时间:2024/06/05 09:55
Q: How to use 'GetItemData()' and 'SetItemData()'?
A: A tree control is just a visual representation of some hierarchical data structure. You use 'SetItemData()' and 'GetItemData()' to link each tree item to a node if this data structure.
Firstly you have to define a class or a structure that holds the data for each node. For example if your tree is supposed to show a file system, the structure you define will reflect all the properties of a file, like name, size, timestamp, whether it is a directory or not, access rights and so on. The tree will display only the name. Each of the trees items will be linked to an instance of such a structure.
'SetItemData()' allows you to attach a 'DWORD' to each item and 'GetItemData()' allows you to get that 'DWORD' back. A plain 'DWORD' isn't of much use, but luckily under Windows a 'DWORD' and a pointer have the same size, so you can cast forth and back between them.
When you add an item to the tree, you attach a pointer to a 'node_data' structure to that item:
When you handle an operation on some item of the tree (for example selection) you retrieve the node using 'GetItemData()':
A: A tree control is just a visual representation of some hierarchical data structure. You use 'SetItemData()' and 'GetItemData()' to link each tree item to a node if this data structure.
Firstly you have to define a class or a structure that holds the data for each node. For example if your tree is supposed to show a file system, the structure you define will reflect all the properties of a file, like name, size, timestamp, whether it is a directory or not, access rights and so on. The tree will display only the name. Each of the trees items will be linked to an instance of such a structure.
Code:
struct node_data{ //...};
When you add an item to the tree, you attach a pointer to a 'node_data' structure to that item:
Code:
HTREEITEM hItem = m_tree.InsertItem(/*...*/);node_data *node = new node_data();// Fill up the new nodenode->member = value; //...// Attach the node to the itemm_tree.SetItemData(hItem, (DWORD) node);
Code:
// 'hItem' is a valid iten handlenode_data *node = (node_data *) m_tree.GetItemData(hItem);// Retrieve, set or take decisions according to the nodes // membersif(node->member == some_value) some_action();value = node->member;node->member = value;
- How to use 'SetItemData()' and 'GetItemData()'?
- How to use 'SetItemData()' and 'GetItemData()'?
- 关于SetItemData和GetItemData
- 关于Combobox SetItemData与GetItemData
- CListCtrl中SetItemData和GetItemData的用法
- MFC Combox SetItemData与GetItemData使用实例
- How to install and use doxygen
- How to Create and Use the DLL
- How To Use Function 'F4_FILENAME' and 'KD_GET_FILENAME_ON_F4'
- standard exception and how to use
- How to use the CONVERSION_EXIT_PARVW_INPUT and CONVERSION_EXIT_PARVW_OUTPUT
- How To Choose and Use Strong Passwords
- how to config and use apt-get
- What and How to use JSF
- How to use NSString and NSMutableString
- How to use appreciation and lie
- How to use calltree and Graphviz/CodeViz
- How to configure and use CAN bus
- Ubuntu9.10下安装配置tftp服务器
- Ubuntu安装Tenda W311P 无线PCI网卡(转)
- [Accelerated c++读书笔记] 读入一行,拆分每个word。
- 解决Godaddy域名解析故障
- ubuntu9.10下安装配置NFS服务
- How to use 'SetItemData()' and 'GetItemData()'?
- Linux开机自动运行程序
- linux中bin和sbin目录的主要区别
- 检测iphone设备是否越狱
- Robot Framework 安装及使用指南
- Linux下网络配置总结、
- 代理与动态代理
- cocos2d-x 在新thread中调用opengles绘制函数会出错
- Java web(2012/2/21)