mctrl icon indicating copy to clipboard operation
mctrl copied to clipboard

Treelist: Add a message(s) to get currently selcted item (or items)

Open dido2k opened this issue 5 years ago • 5 comments

Hi, Martin.

I did not manage to find how to get the treelist selection. I am trying to get the clicked item on NM_DBLCLK notification.

  1. HTREEITEM hSelectedItem = TreeView_GetSelection(lpNmHdr->hwndFrom);
  2. int iPos = ListView_GetNextItem(lpNmHdr->hwndFrom, -1, LVNI_SELECTED | LVNI_FOCUSED);

But both methods don't work. Would you help a bit?

Kind Regards, Diyan.

dido2k avatar Apr 10 '20 14:04 dido2k

I got it.

GetCursorPos(&pt);
ScreenToClient(lpNmHdr->hwndFrom, &pt);
MC_TLHITTESTINFO hitTestInfo;
ZeroMemory(&hitTestInfo, sizeof(MC_TLHITTESTINFO));
hitTestInfo.pt = pt;
SendMessage(lpNmHdr->hwndFrom, MC_TLM_HITTEST, 0, (LPARAM)&hitTestInfo);
if (hitTestInfo.flags != MC_TLHT_NOWHERE && hitTestInfo.hItem) {
        MC_TLITEM item;
        ZeroMemory(&item, sizeof(MC_TLITEM));
        item.fMask = MC_TLIF...
        SendMessage(lpNmHdr->hwndFrom, MC_TLM_GETITEM, (WPARAM)hitTestInfo.hItem, (LPARAM)&item);```
}

Thanks.

dido2k avatar Apr 10 '20 15:04 dido2k

Not an issue.

dido2k avatar Apr 10 '20 15:04 dido2k

Humm, reopening. It is an issue.

Having some API for that would be highly useful and lack of it seems as an unintended ommission to me, especially as we have MC_TLM_GETSELECTEDCOUNT.

mity avatar Apr 10 '20 16:04 mity

After all, it is implemented. It follows the standard treeview control as a model here, including its possibly not so good naming convention:

The message MC_TLM_GETNEXTITEM accepts the flag MC_TLGN_CARET (in WPARAM), which returns a selected item:

  • If LPARAM is NULL, it returns the 1st selected item.

  • If LPARAM is not NULL, it returns the next selected item after the one provided. (I believe Vista has added TVGN_NEXTSELECTED for that but this part of our API was possibly designed before Vista. We could add MC_TLGN_NEXTSELECTED for the sake of consistency.)

So, the main difference here is we don't provide the wrapping macros like TreeView_GetSelection(hwnd), which actually is just a synonym for SendMessage(hwnd, TVM_GETNEXTITEM, (WPARAM) TVGN_CARET, (LPARAM) NULL).

mity avatar Apr 10 '20 19:04 mity

Thank you, Martin. I appreciate It.

dido2k avatar Apr 10 '20 21:04 dido2k