要将功能区菜单添加到现有的MFC应用程序,请按照以下步骤操作:
ON_MESSAGE(WM_CREATE, OnCreate)
LRESULT CMainFrame::OnCreate(WPARAM wParam, LPARAM lParam)
{
LRESULT lResult = CMDIFrameWndEx::OnCreate(wParam, lParam);
if (!m_wndRibbonBar.Create(this))
{
return -1;
}
return lResult;
}
void CMainFrame::InitializeRibbon()
{
CMFCRibbonMainPanel* pMainPanel = m_wndRibbonBar.AddMainCategory(_T("File"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
// 在此处添加功能区面板和按钮
}
void CMainFrame::InitializeRibbon()
{
CMFCRibbonMainPanel* pMainPanel = m_wndRibbonBar.AddMainCategory(_T("File"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
// 添加“新建”按钮
CMFCRibbonButton* pNewButton = new CMFCRibbonButton(ID_FILE_NEW, _T("New"), 0, 0);
pMainPanel->Add(pNewButton);
// 添加“打开”按钮
CMFCRibbonButton* pOpenButton = new CMFCRibbonButton(ID_FILE_OPEN, _T("Open"), 1, 1);
pMainPanel->Add(pOpenButton);
// 添加“保存”按钮
CMFCRibbonButton* pSaveButton = new CMFCRibbonButton(ID_FILE_SAVE, _T("Save"), 2, 2);
pMainPanel->Add(pSaveButton);
// 添加其他面板和按钮
}
void CMainFrame::InitializeRibbon()
{
CMFCRibbonMainPanel* pMainPanel = m_wndRibbonBar.AddMainCategory(_T("File"), IDB_RIBBON_FILE_SMALL, IDB_RIBBON_FILE_LARGE);
// 添加“新建”按钮
CMFCRibbonButton* pNewButton = new CMFCRibbonButton(ID_FILE_NEW, _T("New"), 0, 0);
pMainPanel->Add(pNewButton);
// 添加“打开”按钮
CMFCRibbonButton* pOpenButton = new CMFCRibbonButton(ID_FILE_OPEN, _T("Open"), 1, 1);
pMainPanel->Add(pOpenButton);
// 添加“保存”按钮
CMFCRibbonButton* pSaveButton = new CMFCRibbonButton(ID_FILE_SAVE, _T("Save"), 2, 2);
pMainPanel->Add(pSaveButton);
// 添加其他面板和按钮
CMFCRibbonCategory* pCategory = m_wndRibbonBar.AddCategory(_T("Edit"), IDB_RIBBON_EDIT_SMALL, IDB_RIBBON_EDIT_LARGE);
CMFCRibbonPanel* pEditPanel = pCategory->AddPanel(_T("Editing"));
// 添加“剪切”按钮
CMFCRibbonButton* pCutButton = new CMFCRibbonButton(ID_EDIT_CUT, _T("Cut"), 0, 0);
pEditPanel->Add(pCutButton);
// 添加“复制”按钮
CMFCRibbonButton* pCopyButton = new CMFCRibbonButton(ID_EDIT_COPY, _T("Copy"), 1, 1);
pEditPanel->Add(pCopyButton);
// 添加“粘贴”按钮
CMFCRibbonButton* pPasteButton = new CMFCRibbonButton(ID_EDIT_PASTE, _T("Paste"), 2, 2);
pEditPanel->Add(pPasteButton);
}
void CMainFrame::InitializeRibbon
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云