【问题标题】:Ribbon UI dynamic button menu edit功能区 UI 动态按钮菜单编辑
【发布时间】:2016-01-06 08:52:59
【问题描述】:

我有一个带有功能区 UI 的应用程序。在此 UI 中,存在一个按钮,并附有一个菜单。我想做的是从按钮处理程序访问菜单以动态添加和删除菜单项。

void
CMyScrollView::OnMenuButtonHandler ()
{
  // TODO: Add your command handler code here
  CMFCRibbonBar *pRibbon  = ((CMDIFrameWndEx*)GetTopLevelFrame())GetRibbonBar()
  // Control ID_BTN_EDIT_MENU
  // This where I would like to isolate and vary menu contents
}

【问题讨论】:

    标签: c++ mfc windows-ribbon-framework


    【解决方案1】:

    在 CMainFRame 窗口中为 AFX_WM_ON_BEFORE_SHOW_RIBBON_ITEM_MENU 消息 (ON_REGISTERED_MESSAGE) 创建一个处理程序。

    检查按钮的 ID。删除所有以前的项目并添加你想要的。

    LRESULT CMainFrame::OnBeforeShowRibbonItemMenu(WPARAM,LPARAM lp)
    {
      CMFCRibbonBaseElement *pElement = reinterpret_cast<CMFCRibbonBaseElement*>(lp);
    
      // Try to get our menu button
      switch (pElement->GetID())
      {
        case ID_RIBBON_DROPDOWN_BUTTON:
        {
          CMFCRibbonButton *pButton = DYNAMIC_DOWNCAST(CMFCRibbonButton, pElement);
          if (pButton)
          {
            // MY_LIST copntains members with the ID and the text: m_uiCmdId, m_strTitle
            const MY_LIST &list = ....;
            if (list.size()!=0)
            {
              pButton->RemoveAllSubItems();
    
              for (it = list.begin(); it!=list.end(); ++it)
                pButton->AddSubItem(new CSomeKindOfRibbonButton(it->m_uiCmdId, it->m_strTitle));
            }
          }
     ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      相关资源
      最近更新 更多