Detect clicking inside listview and show context menu

有些话、适合烂在心里 提交于 2019-12-04 12:47:18

NM_RCLICK is your friend.

But it doesn't solve the whole problem, such as displaying a context menu when user hits the Windows menu key on his keyboard. This KB article shows how to combine NM_RCLICK and WM_CONTEXTMENU. (It's for the CTreeCtrl but adapting the code to CListView is trivial).

You will have OnContextMenu handler called regardless of click position within the listview. Now your task is to see where exactly click happened and decide on the action you want.

Your question make me think that you grabbed the code with ListView_GetFocusedGroup from internet as opposed to intentially writing it yourself. What you need to do however, is to send "hit test" message back to list view providing the point of interest (which is the click point): ListView_HitTest, ListView_HitTestEx.

Having this done you obtain the item and/or subitem in this location, and you can decide what to do next.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!