You are handling the
NM_CLICK
notification which is send when clicking the left button within the tree control. So there is no need to check if the left button is down.
But when this message is handled by your code, the default handling has not yet been called so that the clicked item is not yet selected.
To get the clicked item you can use something like
UINT uFlags = 0;
CPoint pt(0, 0);
GetCursorPos(&pt);
m_treeRel.ScreenToClient(&pt);
HTREEITEM hItem = m_treeRel.HitTest(pt, &uFlags);
if(NULL != hItem && (TVHT_ONITEM & uFlags))
{
}
It is not quite clear what you finally want to achieve. But there are often multiple notifications and messages that might be used for specific tasks. So you should also have a look at these. A candidate might be the
TVN_SELCHANGING notification code (Windows)[
^].