Menu MFC:第二个模式对话框的内容菜单未显示
我有一个带有列表控件的模态对话框。右键单击列表控件中的一项,将显示内容菜单。单击此弹出菜单,打开另一个带有其他列表控件的模式对话框 我的问题是无法在第二个对话框中显示列表控件的右键单击内容菜单 我试过:Menu MFC:第二个模式对话框的内容菜单未显示,menu,mfc,modal-dialog,Menu,Mfc,Modal Dialog,我有一个带有列表控件的模态对话框。右键单击列表控件中的一项,将显示内容菜单。单击此弹出菜单,打开另一个带有其他列表控件的模式对话框 我的问题是无法在第二个对话框中显示列表控件的右键单击内容菜单 我试过: void CMyListCtrl::OnContextMenu(CWnd* , CPoint point) { if (GetSelectedCount() == 0) return ; if (point.x == -1 && point.y
void CMyListCtrl::OnContextMenu(CWnd* , CPoint point)
{
if (GetSelectedCount() == 0)
return ;
if (point.x == -1 && point.y == -1)
{
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(IDR_HISTORY_MENU));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this->GetParent();
SetForegroundWindow();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
point.x,
point.y,
pWndPopupOwner);
}
我还添加到了\u WM\u INITMENUPOPUP上的父对话框中
还尝试在运行中创建一个弹出菜单
void CHistoryListCtrl::OnContextMenu(CWnd* , CPoint point)
{
if (GetSelectedCount() == 0)
return ;
if (point.x == -1 && point.y == -1)
{
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu addMenu;
addMenu.CreatePopupMenu();
// add all possible interface items
CString mstr; mstr="Compare";
addMenu.AppendMenu(MF_ENABLED | MF_STRING,ID_HISTORY_COMPARE , (LPCTSTR)mstr);
addMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,point.x,point.y,this,NULL);
addMenu.DestroyMenu();
}
但效果不太好。尝试在调用TrackPopupMenu之前添加SetForgroundWindow,但也失败
你知道该怎么做吗?你是说弹出菜单根本不显示,还是说在弹出菜单中选择一个项目没有任何作用?调用
TrackPopupMenu()
返回什么值?我想您需要插入这一行:theApp.OnIdle(-1)代码>在调用TrackPopupMenu()之前,让我澄清一下,当作为第一个模式对话框调用时,弹出菜单工作得非常好。当另一个模态对话框调用此对话框时,列表控件的弹出菜单不起作用