Something like this
HTREEITEM hSelectedItem = TreeView_GetSelection(hwnd);
if (hSelectedItem == NULL)
return;
TCHAR buffer[128];
TVITEM item;
item.hItem = hSelectedItem;
item.mask = TVIF_TEXT;
item.cchTextMax = 128;
item.pszText = buffer;
if (TreeView_GetItem(hwnd, &item))
{
cout << item.pszText << " is selected" << endl;
}