Search code examples
c++mfctreecontrol

Add item to tree control


I have an object of the my own class and CTreeCtrl. I have opportunity add items to CTreeCtrl like

hTree = treeObject->InsertItem(L"All object", TVI_ROOT);

This code add items with text. Have i opportunity to add items with consist pointer of my object?


Solution

  • As @πάντα ῥεῖ suggests, SetItemData is the way to go. The type of the parameter should be DWORD_PTR allowing both 64-bit and 32-bit code to use the data as a pointer. You will have to cast the pointer. Read up on the methods of CTreeCtrl for more information.