MFC之右键点击listctrl控件弹出菜单

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41485242/article/details/79282550

先自己在资源视图中添加IDR_POPUP_EDIT_LIST菜单

然后在类向导中为listctrl控件添加NM_RCLICK命令

然后添加响应函数:

void CYourDialog::OnRclickParaslist(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pNMListView->iItem != -1)
{
DWORD dwPos = GetMessagePos();
CPoint point(LOWORD(dwPos), HIWORD(dwPos));


CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP_EDIT_LIST));
CMenu* popup = menu.GetSubMenu(0);
ASSERT(popup != NULL);
popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
}
*pResult = 0;
}

over!

展开阅读全文

没有更多推荐了,返回首页