|
I saw almost all (kinda exaggerated) projects using
ListView and TreeView will store user data in ItemData.
The regular method is casting a pointer of the user
data to and from DWORD_PTR, then using the Get(Set)ItemData
to store/retrieve the casted pointer, like this
struct MyData
{
// user data
};
MyData *data = new MyData
listview.SetItemData(0, (DWORD_PTR)data);
.... in other place,
MyData *data2 = (MyData*)listview.GetItemData(0);
Could WTL add a new template parameter to CListViewCtrlT
like this:
template <class TBase, class TData=DWORD_PTR>
class CListViewCtrlT : public TBase
{
....
TData GetItemData(int nItem) const
{
....
}
BOOL SetItemData(int nItem, TData dwData)
{
....
}
...
}
then we can use CListViewCtrlT in this way:
CListViewCtrlT<CWindow,MyData*> listview;
MyData *data = new MyData
listview.SetItemData(0, data);
.... in other place,
MyData *data2 = listview.GetItemData(0);
Thus, no cast needed. How do you think about it?
Best Regards
gchen
|