GetMenuItemInfo & InsertMenuItem 枚举和追加菜单操作

来源:互联网 发布:营销软件破解版 编辑:程序博客网 时间:2024/05/01 15:57



int _AppendMenuOp(HMENU hDst, HMENU hSrc){  int iCnt = 0;    ASSERT(hDst && hSrc);  for(int iSrc=0, iDst=GetMenuItemCount(hDst); iSrc<GetMenuItemCount(hSrc); iSrc++)  {    TCHAR szMenuStr[256] = {0};    MENUITEMINFO mInfo = {0};    mInfo.cbSize = sizeof(mInfo);    mInfo.fMask = 0      | MIIM_CHECKMARKS //Retrieves or sets the hbmpChecked and hbmpUnchecked members.       | MIIM_DATA //Retrieves or sets the dwItemData member.       | MIIM_ID //Retrieves or sets the wID member.       | MIIM_STATE //Retrieves or sets the fState member.       | MIIM_SUBMENU //Retrieves or sets the hSubMenu member.       | MIIM_TYPE //Retrieves or sets the fType and dwTypeData members.       | 0;    mInfo.dwTypeData = szMenuStr;    mInfo.cch = _countof(szMenuStr);    VERIFY(GetMenuItemInfo(hSrc, iSrc, TRUE, &mInfo));    if(mInfo.hSubMenu)    {      HMENU hSub = CreatePopupMenu();      _AppendMenuOp(hSub, mInfo.hSubMenu);      mInfo.hSubMenu = hSub;                        }    InsertMenuItem(hDst, iDst++, TRUE,  &mInfo);    iCnt++;  }  return iCnt;}void CDlg3Dlg::OnContextMenu(CWnd* pWnd, CPoint point) {  // TODO: Add your message handler code here  CMenu m1,m2, pm;  m1.LoadMenu(IDR_MENU1);  m2.LoadMenu(IDR_MENU2);  pm.CreatePopupMenu();  _AppendMenuOp(pm.m_hMenu, m1.m_hMenu);  pm.AppendMenu(MF_SEPARATOR, 0, _T(""));  _AppendMenuOp(pm.m_hMenu, m2.m_hMenu);   pm.TrackPopupMenu(0, point.x, point.y, this);}


0 0
原创粉丝点击