以下为具体步骤:
在Resource.h中添加ID声明:
#define IDM_HELLO 111
在MainFrm.cpp中添加菜单代码:
CMenu menu;
menu.CreatePopupMenu();
//GetMenu()->AppendMenuA(MF_POPUP,(UINT)menu.m_hMenu,"Lyunjun");
GetMenu()->InsertMenuA(2,MF_BYPOSITION |MF_POPUP,(UINT)menu.m_hMenu,"Lyunjun");
menu.AppendMenuA(MF_STRING,IDM_HELLO,"hello luo");
menu.AppendMenuA(MF_STRING,112,"hello yun");
menu.AppendMenuA(MF_STRING,113,"hello jun");
MainFrm.h中添加函数声明:
afx_msg void Onhello();
MainFrm.cpp中添加消息响应:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(IDM_HELLO,Onhello) //新加的消息响应
END_MESSAGE_MAP()
MainFrm.cpp中添加函数实现:
void CMainFrame::Onhello()
{
MessageBox("hello Mr.Luo");
}
如下图: