Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dido2k opened this issue Apr 10, 2020 · 5 comments
Open

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

dido2k opened this issue Apr 10, 2020 · 5 comments

Comments

@dido2k
Copy link

dido2k commented Apr 10, 2020

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
Copy link
Author

dido2k commented Apr 10, 2020

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 dido2k closed this as completed Apr 10, 2020
@dido2k
Copy link
Author

dido2k commented Apr 10, 2020

Not an issue.

@mity
Copy link
Owner

mity commented Apr 10, 2020

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 mity reopened this Apr 10, 2020
@mity mity changed the title Unable to find selected item in treelist Treelist: Add a message(s) to get currently selcted item (or items) Apr 10, 2020
@mity
Copy link
Owner

mity commented Apr 10, 2020

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).

@dido2k
Copy link
Author

dido2k commented Apr 10, 2020

Thank you, Martin. I appreciate It.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants