我有一个带有列表控件的模态对话框。右键单击列表控件中的一个项目,显示内容菜单。单击此弹出菜单,打开另一个带有另一个列表控件的模式对话框。
我的问题是我无法在第二个对话框中为列表控件显示右键单击内容菜单。
我试过了:
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);
}
我也加入了父对话框ON_WM_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,但它也失败了。
知道该怎么做?