MFC listctrl控件右键关联菜单
1.准备一个菜单ID_RAWDATAPAGE_LISTCTRL
2.添加listctrl 控件的消息NM_RCLICK
ON_NOTIFY(NM_RCLICK, ID_RAWDATAPAGE_LISTCTRL, &CHeightAnormalRawDataPage::OnRclickListCtrl)
3.编写消息响应函数:
void CHeightAnormalRawDataPage::OnRclickListCtrl(NMHDR *pNMHDR, LRESULT *pResult)
{
MessageBox("Clicked GridCtrl");
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
CMenu menu, *pPopup;
menu.LoadMenu(IDR_MENU_PROJECTION);
pPopup = menu.GetSubMenu(0);
CPoint myPoint;
ClientToScreen(&myPoint);
GetCursorPos(&myPoint); //鼠标位置
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, myPoint.x, myPoint.y, GetParent());
*pResult = 0;
}