0
我嘗試了以下所有可找到的示例,但我錯過了一些東西,因此我將所有作品放在此處供其他人查看。僅供參考 - 我正在修改MFC Feature Pack示例滑塊。將一個下拉菜單按鈕添加到CMFCToolbar,看不到菜單
我看到圖層按鈕(不是一個字符串或向下的箭頭),如果我選擇按鈕(單擊)我看到壓下動作,並與按鈕的ID到OnLayers()函數。我幾乎看起來像ReplaceButton()什麼都不做。
任何想法?
感謝
因爲我已經添加ID_LAYERS_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)
{
}