<p>I have tree control object created using CTreeCtrl MFC class. The tree control needs to support rename.
When I left click on any of item in Tree the TVN_SELCHANGED event is called from which I can get the selected item of the tree as below :
  HTREEITEM h = m_moveListTree.GetSelectedItem();
  CString s = m_moveListTree.GetItemText(h);</p>

<p>However when I rightclick on any item in tree I do not get any TVN_SELCHANGED event and hence my selected item still remains the same from left click event. This is causing following problem :
1)User leftclicks on item A
2)user right clicks on item B and says rename
3)Since the selected item is still A the rename is applying for item A.</p>

<p>Please help in solving problem.</p>

<p>-Praveen</p>

I created my own MFC like home grown C++ GUI library on top of the Win32 API and looking at my code, this is how it handles that situation:
```
```
LRESULT xTreeCtrl::onRightClick(NMHDR *)
{
  xPoint pt;

  //-- get the cursor at the time the mesage was posted
  DWORD dwPos = ::GetMessagePos();

  pt.x = GET_X_LPARAM(dwPos);
  pt.y = GET_Y_LPARAM (dwPos);

  //-- now convert to window co-ordinates
  pt.toWindow(this);

  //-- check for a hit
  HTREEITEM hItem = this->hitTest(pt);

  //-- select any item that was hit
  if ((int)hItem != -1) this->select(hItem);

  //-- leave the rest to default processing
  return 0;
}
```
```
I suspect if you do something similar in the MFC right click or right button down events that will fix the problem.
NOTE: The onRightClick code above is nothing more than the handler for the
WM_NOTIFY
,
NM_RCLICK
message.