0

我有一个带有列表控件的模式对话框。右键单击列表控件中的一项,显示内容菜单。单击此弹出菜单,将打开另一个带有另一个列表控件的模式对话框。

我的问题是我无法在第二个对话框中显示列表控件的右键单击内容菜单。

我试过了:

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,但也失败了。

知道该怎么做吗?

4

0 回答 0