Drop down menu 将下拉菜单按钮添加到CMFCToolbar,不显示菜单

Drop down menu 将下拉菜单按钮添加到CMFCToolbar,不显示菜单,drop-down-menu,cmfctoolbar,Drop Down Menu,Cmfctoolbar,我尝试了所有我能找到的例子,但我遗漏了一些东西,所以我将把所有的片段放在这里供其他人查看。仅供参考-我正在修改MFC功能包示例滑块 我看到图层按钮(不是字符串或向下箭头),如果我选择按钮(单击),我会看到按下运动,并使用按钮ID进入OnLayers()函数。我几乎觉得ReplaceButton()什么都没做 有什么想法吗 谢谢 对于工具栏,我添加了ID\u LAYERS\u 1 IDR_MAINFRAME TOOLBAR 16, 15 BEGIN BUTTON ID_FILE_

我尝试了所有我能找到的例子,但我遗漏了一些东西,所以我将把所有的片段放在这里供其他人查看。仅供参考-我正在修改MFC功能包示例滑块

我看到图层按钮(不是字符串或向下箭头),如果我选择按钮(单击),我会看到按下运动,并使用按钮ID进入OnLayers()函数。我几乎觉得ReplaceButton()什么都没做

有什么想法吗

谢谢

对于工具栏,我添加了ID\u LAYERS\u 1

IDR_MAINFRAME TOOLBAR 16, 15
BEGIN
    BUTTON      ID_FILE_NEW
    BUTTON      ID_FILE_OPEN
    BUTTON      ID_FILE_SAVE
    SEPARATOR
    BUTTON      ID_SLIDER
    SEPARATOR
    BUTTON      ID_EDIT_CUT
    BUTTON      ID_EDIT_COPY
    BUTTON      ID_EDIT_PASTE
    SEPARATOR
    BUTTON      ID_FILE_PRINT
    SEPARATOR
    BUTTON      ID_APP_ABOUT
    SEPARATOR
    BUTTON      ID_LAYERS_1
END
我的菜单是

IDR_LAYERS MENU
BEGIN
    POPUP "Layers"
    BEGIN
        MENUITEM "0",                           ID_LAYERS_1
        MENUITEM "1",                           ID_LAYERS_2
        MENUITEM "2",                           ID_LAYERS_3
    END
END
代码呢

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
   ON_WM_CREATE()
   ON_WM_CLOSE()
   ON_COMMAND(ID_SLIDER, OnSlider)
   ON_COMMAND(ID_VIEW_CUSTOMIZE, OnViewCustomize)
   ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
   ON_REGISTERED_MESSAGE(AFX_WM_TOOLBARMENU, OnToolbarContextMenu)
   ON_UPDATE_COMMAND_UI_RANGE(ID_LAYERS_1, ID_LAYERS_3, OnUpdateLayers)
   ON_COMMAND_RANGE(ID_LAYERS_1, ID_LAYERS_3, OnLayers)
END_MESSAGE_MAP()

CMFCToolBarMenuButton* CreateLayerButton()
{
   CMenu menu;
   VERIFY(menu.LoadMenu(IDR_LAYERS));

   CMFCToolBarMenuButton* pLayerButton = NULL;
   CMenu* pPopup = menu.GetSubMenu(0);
   ASSERT(pPopup != NULL);
   if (pPopup != NULL)
   {
      HMENU hMenu = pPopup->GetSafeHmenu();
      pLayerButton = new CMFCToolBarMenuButton(ID_LAYERS_1, hMenu, -1, NULL, FALSE);
   }

   return pLayerButton;
}

afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM)
{
   UINT uiToolBarId = (UINT)wp;
   if (uiToolBarId == IDR_MAINFRAME)
   {
      CSliderButton btnSlider(ID_SLIDER);
      btnSlider.SetRange(0, 100);
      m_wndToolBar.ReplaceButton(ID_SLIDER, btnSlider);

      // layer button/menu
      CMFCToolBarMenuButton* pLayerButton = CreateLayerButton();
      m_wndToolBar.ReplaceButton(ID_LAYERS_1, *pLayerButton);
      delete pLayerButton;
   }

   return 0;
}

void CMainFrame::OnUpdateLayers(CCmdUI* pCmdUI)
{
   //pCmdUI->SetCheck(true);
}

void CMainFrame::OnLayers(UINT id)
{
}

我认为你用错了。试着这样做:

CMenu menu;
VERIFY(menu.LoadMenu(IDR_LAYERS));

CString str;

str.LoadString (IDS_TEXT_OF_YOUR BUTTON);
m_wndToolBar.ReplaceButton (ID_LAYERS1, 
    CMFCToolBarMenuButton ( (UINT)-1, menu, 
                GetCmdMgr ()->GetCmdImage (ID_LAYERS1), str,TRUE));

我认为你用错了。试着这样做:

CMenu menu;
VERIFY(menu.LoadMenu(IDR_LAYERS));

CString str;

str.LoadString (IDS_TEXT_OF_YOUR BUTTON);
m_wndToolBar.ReplaceButton (ID_LAYERS1, 
    CMFCToolBarMenuButton ( (UINT)-1, menu, 
                GetCmdMgr ()->GetCmdImage (ID_LAYERS1), str,TRUE));

答案对你有用吗?答案对你有用吗?