1、什么是系统菜单?
所谓系统菜单就是指你在应用程序标题栏上鼠标右键操作时弹出的菜单,如下图所示:
2、如何在系统菜单中动态添加菜单项
// 修改系统菜单
CMenu* system_menu;
system_menu = pFrm->GetSystemMenu(false);
system_menu->AppendMenu(MF_SEPARATOR);
system_menu->AppendMenu(MF_STRING,ID_NORMALVIEW,"正常查看(&N)/tF12");
system_menu->AppendMenu(MF_STRING,ID_FULLSCREEN,"全屏幕查看(&F)/tF12");
system_menu->AppendMenu(MF_STRING,ID_STRETCHVIEW,"拉伸模式(&S)/tF12");
system_menu->CheckMenuItem(ID_STRETCHVIEW,MF_BYCOMMAND|MF_CHECKED);
system_menu->AppendMenu(MF_SEPARATOR);
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"发送Ctrl-Alt-&Del/tC-A-F12");
system_menu->AppendMenu(MF_BYPOSITION|MF_POPUP,(UINT)CreatePopupMenu(),"发送特殊键(&K)");
CMenu *pAddinMenu = system_menu->GetSubMenu(system_menu->GetMenuItemCount()-1);
pAddinMenu->AppendMenu(MF_BYPOSITION|MF_STRING|MF_ENABLED,ID_MYMENUITEM,"Ctrl-Esc");
pAddinMenu->AppendMenu(MF_BYPOSITION|MF_STRING|MF_ENABLED,ID_MYMENUITEM,"F12");
pAddinMenu->AppendMenu(MF_BYPOSITION|MF_STRING|MF_ENABLED,ID_MYMENUITEM,"Ctrl-F12");
pAddinMenu->AppendMenu(MF_BYPOSITION|MF_STRING|MF_ENABLED,ID_MYMENUITEM,"Alt-F12");
pAddinMenu->AppendMenu(MF_BYPOSITION|MF_STRING|MF_ENABLED,ID_MYMENUITEM,"Ctrl-Alt-F12");
system_menu->AppendMenu(MF_SEPARATOR);
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"获取剪贴板内容(&G)");
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"设置剪贴板内容(&T)");
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"关机(&W)...");
system_menu->AppendMenu(MF_SEPARATOR);
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"选项(&O)...");
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"连接信息(&I)...");
system_menu->AppendMenu(MF_STRING,ID_MYMENUITEM,"关于(&A)...");
修改后的菜单如下图所示:
3、给菜单项添加消息处理
和普通菜单一样,加入消息处理即可,这里不再赘述。
如果你是VC程序员或爱好者,而且想和大家一起交流你的经验,都可以加入群“VC程序员之家群一(号码:74515881)”或“VC程序员之家群二(号码:30844241)”。