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



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);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值