关闭

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

195人阅读 评论(0) 收藏 举报
分类:



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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:293113次
    • 积分:5132
    • 等级:
    • 排名:第6070名
    • 原创:183篇
    • 转载:0篇
    • 译文:2篇
    • 评论:114条
    最新评论