I have created a treeview at runtime in MFC application , I have added few nodes to it now i want to do some stuff on click of nodes so how i can get click event of treeview ?
My code looks like this :
CTreeCtrl *m_ctlTreeview;
m_ctlTreeview = new CTreeCtrl ;
m_ctlTreeview->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |
TVS_TRACKSELECT,
CRect(25, 60, 385, 260), this, 0x1221);
hparentitem = m_ctlTreeview->InsertItem("Parent",TVI_ROOT);
m_ctlTreeview->InsertItem("Child", hparentitem);
One option is to add a handler for the notification messages for that child window ID (0x1221 in your example) to the parent class at design time using
ON_NOTIFYin the message map as usual. If there are no messages, the handler won’t be triggered.Alternatively, you could add a generic
WM_NOTIFYhandler to the message map of the parent window withON_MESSAGE, and then check to see if the message comes from your new tree control.