Win32 API Select tree view entry by right clicking

Started by
2 comments, last by Hannesnisula 14 years, 6 months ago
Is that possible? I want to be able to right click on any entry and having that right click selecting the entry. Isn't that how like every other windows app works?
Advertisement
AFAIK the default behaviour of tree controls on a right click is to set the clicked item visually as selected, but on button up selected the original item(s) again.

If you want to change that behaviour you need to override PreTranslateMessage (MFC) or subclass the treeview control (WIN32).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

AFAIK, it isn't default behaviour.

The MSDN indicates that when the Tree View control receives a right click, it sends a NM_RCLICK notification (in a WM_NOTIFY) to its parent window.

You could listen for this message and process it with something like this in your parent window's message hander:
    case WM_NOTIFY:        {            LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lParam);	    if(pNMHDR->hwndFrom == hTreeView && pNMHDR->code == NM_RCLICK) {                HTREEITEM hItem = TreeView_GetNextItem(pNMHDR->hwndFrom, 0, TVGN_DROPHILITE);                if(hItem)                    TreeView_SelectItem(pNMHDR->hwndFrom, hItem);            }            break;        }
Thank you for the help!

This topic is closed to new replies.

Advertisement