Detect clicking inside listview and show context menu
I have a listview created as a resource and loaded on a dialog window. I want to detect and show a context menu only when items within the listview have been clicked. MESSAGE_HANDLER(WM_CONTEXTMENU,OnContextMenu) LRESULT OnContextMenu(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { int iSelected = -1; int iFocusGroup = -1; iSelected = SendMessage((HWND)wParam, LVM_GETNEXTITEM, -1,LVNI_SELECTED); iFocusGroup = ListView_GetFocusedGroup((HWND)wParam); if( iSelected != -1 && iFocusGroup == -1) { hPopupMenu = CreatePopupMenu(); Insert Menu(hPopupMenu, 0, MF_BYCOMMAND | MF_STRING | MF