1.菜单索引号确定菜单的索引号,注意从 0 开始,分隔符也算数。什么叫弹出菜单(Popup Menu)?一个
子菜单只能有一个缺省菜单。
1 //GetMenu()->GetSubMenu(0)->SetDefaultItem(5,TRUE); 2 str.Format("x=%d,y=%d",GetSystemMetrics(SM_CXMENUCHECK), 3 GetSystemMetrics(SM_CYMENUCHECK));//获得系统的菜单的位图的大小。 4 /* SetMenu(NULL);//移除菜单 CMenu menu; 5 menu.LoadMenu(IDR_MAINFRAME); 6 SetMenu(&menu); 7 menu.Detach();*/增加菜单,此处 detach(),如果是局部变量。
2.设置菜单可用情况
1 void CMainFrame::OnUpdateEditCut(CCmdUI* pCmdUI) 2 {4 pCmdUI->Enable();//当此菜单显示时,设为可用。 5 }
3.右键弹出菜单程序
两种方法1.添加控件Project->Add to Project->component and controls->文件夹 VC components->Popup Menu OK
2.自己创建函数TrackPopupMenu(),在右键响应函数中确定
1 CMenu menu; 2 menu.LoadMenu(IDR_MENU1);//menu1 实在资源视图中自己创建的函数 3 CMenu *pPopup=menu.GetSubMenu(0); 4 ClientToScreen(&point); //这句话是坐标和菜单对应 5 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, 6 GetParent());
4.创建动态菜单
1 CMenu menu; 2 menu.CreatePopupMenu();//创建弹出菜单 3 // GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,"WinSun"); 4 GetMenu()->InsertMenu(2,MF_BYPOSITION | 5 MF_POPUP,(UINT)menu.m_hMenu,"WinSun"); 6 menu.AppendMenu(MF_STRING,IDM_HELLO,"Hello"); 7 menu.AppendMenu(MF_STRING,112,"Weixin"); 8 menu.AppendMenu(MF_STRING,113,"Mybole"); 9 menu.Detach(); 10 GetMenu()->GetSubMenu(0)->AppendMenu(MF_STRING,114,"Welcome"); 11 GetMenu()->GetSubMenu(0)->InsertMenu(ID_FILE_OPEN, 12 MF_BYCOMMAND | MF_STRING,115,"维新"); 13 // GetMenu()->DeleteMenu(1,MF_BYPOSITION); 14 // GetMenu()->GetSubMenu(0)->DeleteMenu(2,MF_BYPOSITION);
时间: 2024-10-18 14:10:22