mctrl
mctrl copied to clipboard
Treelist: Add a message(s) to get currently selcted item (or items)
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.
- HTREEITEM hSelectedItem = TreeView_GetSelection(lpNmHdr->hwndFrom);
- 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.
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.
Not an issue.
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.
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
LPARAMisNULL, it returns the 1st selected item. -
If
LPARAMis notNULL, it returns the next selected item after the one provided. (I believe Vista has addedTVGN_NEXTSELECTEDfor that but this part of our API was possibly designed before Vista. We could addMC_TLGN_NEXTSELECTEDfor 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).
Thank you, Martin. I appreciate It.