(一)、实现Popup菜单。
1、定义宏定义,也就是菜单项
#define IDM_MENU0 WM_USER+200
#define IDM_MENU1 WM_USER+201
#define IDM_MENU2 WM_USER+202
#define IDM_MENU3 WM_USER+203
#define IDM_ITEM0 WM_USER+210
#define IDM_ITEM1 WM_USER+211
#define IDM_ITEM2 WM_USER+212
#define IDM_ITEM3 WM_USER+213
#define IDM_ITEM4 WM_USER+214
#define IDM_ITEM5 WM_USER+215
#define IDM_ITEM6 WM_USER+216
#define IDM_ITEM7 WM_USER+217
#define IDM_ITEM8 WM_USER+218
#define IDM_ITEM9 WM_USER+219
#define IDM_ITEM10 WM_USER+220
#define IDM_ITEM11 WM_USER+221
#define IDM_ITEM12 WM_USER+222
#define IDM_ITEM13 WM_USER+223
#define IDM_ITEM14 WM_USER+224
#define IDM_ITEM15 WM_USER+225
#define IDM_ITEM16 WM_USER+226
2、创建CMenu对象
在头文件中定义,CMenu *m_pMenu;
在OnInitDialog中添加实现
m_pMenu = new CMenu();
m_pMenu->LoadMenu(IDR_WinGuoSearch);
#if 0
m_pMenu2 = new CMenu();
m_pMenu2->LoadMenu(IDR_WinGuoSearch);
m_pMenu->AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT)m_pMenu3->GetSubMenu(0)->m_hMenu,L"测试子菜单");
m_pMenu->AppendMenu(MF_STRING,IDM_ITEM0,L"升级");
m_pMenu->AppendMenu(MF_SEPARATOR,IDM_ITEM3,L"");
m_pMenu3 = new CMenu();
m_pMenu3->CreatePopupMenu();
//第二个参数是菜单的句柄HMENU
m_pMenu3->AppendMenu(MF_STRING,IDM_ITEM6,L"每周更新");
m_pMenu3->AppendMenu(MF_STRING,IDM_ITEM7,L"没两周更新");
m_pMenu3->AppendMenu(MF_STRING,IDM_ITEM8,L"每月更新");
m_pMenu3->AppendMenu(MF_STRING,IDM_ITEM9,L"暂不更新");
m_pMenu->AppendMenu(MF_BYPOSITION|MF_POPUP|MF_STRING,(UINT)m_pMenu3->m_hMenu,L"更新设置");
m_pMenu->AppendMenu(MF_STRING,IDM_ITEM2,L"提醒设置");
m_pMenu->AppendMenu(MF_SEPARATOR,IDM_ITEM3,L"");
m_pMenu->AppendMenu(MF_STRING,IDM_ITEM4,L"帮助");
m_pMenu->AppendMenu(MF_STRING,IDM_ITEM5,L"关于");
#endif
3、添加消息映射函数,实现菜单项的事件处理。
ON_COMMAND(IDM_ITEM0, &CWinGuoSearchDlg::OnUpdateWinGuo)
//显示菜单
m_pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_BOTTOMALIGN,0,230+25,this,NULL);
m_pMenu = new CMenu();
m_pMenu->LoadMenu(IDR_WinGuoSearch);
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_BOTTOMALIGN,0,230+25,this,NULL);
评论