MFC中的菜单(Menu)

参考:https://blog.csdn.net/q5512049/article/details/48159165

右键菜单的使用

1. 定义成员变量 CMenu m_menu;
2. 添加消息WM_CREATE消息的函数,OnCreate函数中,

    m_menu.CreatePopupMenu();
    m_menu.AppendMenu(MF_STRING, IDM_ITEM0, L"拷贝");
    m_menu.AppendMenu(MF_STRING, IDM_ITEM1, L"剪切");
    m_menu.AppendMenu(MF_STRING, IDM_ITEM2, L"粘贴");
    m_menu.AppendMenu(MF_SEPARATOR, IDM_ITEM3, L"");
    m_menu.AppendMenu(MF_STRING, IDM_ITEM4, L"全选");
    m_menu.AppendMenu(MF_SEPARATOR, IDM_ITEM5, L"");
    m_menu.AppendMenu(MF_STRING, IDM_ITEM6, L"删除");

3. 类向导添加 WM_RBUTTONUP 的响应函数,并写

void CtestMenuDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
    // TODO:  在此添加消息处理程序代码和/或调用默认值
    //显示菜单
    ClientToScreen(&point);
    m_menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this, NULL);

    CDialogEx::OnRButtonUp(nFlags, point);
}

 

posted @ 2020-03-12 21:28  htj10  阅读(817)  评论(0编辑  收藏  举报
TOP