c++cwinapitreeviewcommon-controls

C/C++ Common Controls detecting double-click of TVItem


Is there any way to detect if a tree view control (and specifically a TVITEM) is double clicked using Common Controls & WINAPI? I mean in my wndproc function of a form.

If so, what are the msg, wParam & lParam in that case?


Solution

  • A treeview control sends an NM_DBLCLK notification when you double-click it, with uMsg = WM_NOTIFY and lParam pointing to an NMHDR structure as per the documentation.

    You can then send the treeview control a TVM_HITTEST message to determine the item under the cursor, something like:

    TVHITTESTINFO tvhti = {};
    GetCursorPos (&tvhti.pt);
    ScreenToClient (hTreeView, &tvhti.pt);
    SendMessage (hTreeView, TVM_HITTEST, 0, (LPARAM) &tvhti);
    

    See the documentation for the values returned by TVM_HITTEST.