vs2010增加新菜单



以下为具体步骤:

在Resource.h中添加ID声明:

  1. #define IDM_HELLO               111  
#define IDM_HELLO				111

在MainFrm.cpp中添加菜单代码:

  1. CMenu menu;  
  2.     menu.CreatePopupMenu();  
  3.     //GetMenu()->AppendMenuA(MF_POPUP,(UINT)menu.m_hMenu,"Lyunjun");   
  4.     GetMenu()->InsertMenuA(2,MF_BYPOSITION |MF_POPUP,(UINT)menu.m_hMenu,"Lyunjun");    
  5.     menu.AppendMenuA(MF_STRING,IDM_HELLO,"hello luo");  
  6.     menu.AppendMenuA(MF_STRING,112,"hello yun");  
  7.     menu.AppendMenuA(MF_STRING,113,"hello jun");  
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中添加函数声明:

  1. afx_msg void Onhello();  
afx_msg void Onhello();

MainFrm.cpp中添加消息响应:

  1. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)  
  2.     ON_WM_CREATE()  
  3.     ON_COMMAND(IDM_HELLO,Onhello)   //新加的消息响应  
  4. END_MESSAGE_MAP()  
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_CREATE()
	ON_COMMAND(IDM_HELLO,Onhello)   //新加的消息响应
END_MESSAGE_MAP()

MainFrm.cpp中添加函数实现:

  1. void CMainFrame::Onhello()  
  2. {  
  3.     MessageBox("hello Mr.Luo");  
  4. }  
void CMainFrame::Onhello()
{
	MessageBox("hello Mr.Luo");
}
如下图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值