LRESULT CMainFrame::OnChangeRibbonCategory(WPARAM,LPARAM) { if (!m_wndOutput.IsAutoHideMode ()) { m_wndOutput.SetRedraw (FALSE); } m_wndOutput.ClearTabs (); CMFCRibbonCategory* pCategory = m_wndRibbonBar.GetActiveCategory (); if (pCategory != NULL) { ASSERT_VALID (pCategory); for (int i = 0; i < pCategory->GetPanelCount (); i++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel (i); ASSERT_VALID (pPanel); m_wndOutput.AddTab (pPanel->GetName (), (UINT)pPanel->GetData ()); } } if (!m_wndOutput.IsAutoHideMode ()) { m_wndOutput.SetRedraw (); m_wndOutput.RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); } return 0; }
BOOL CMainFrame::CreateRibbonBar () { if (!m_wndRibbonBar.Create(this)) { return FALSE; } // Load panel images: m_PanelImages.SetImageSize (CSize (16, 16)); m_PanelImages.Load (IDB_RIBBON_ICONS); if (!m_wndRibbonBar.LoadFromResource(IDR_RIBBON)) { // Add main panel: Add_MainPanel (); Add_Category1 (); Add_Category2 (); Add_Category3 (); Add_Category4 (); Add_Category5 (); Add_Category6 (); // Add quick access toolbar commands: Add_QAT (); // Add "Style" button to the right of tabs: CMFCRibbonButton* pStyleButton = new CMFCRibbonButton ((UINT)-1, _T("Style\ns"), -1, -1); pStyleButton->SetMenu (IDR_THEME_MENU, TRUE /* Right align */); m_wndRibbonBar.AddToTabs (pStyleButton); // Add "About" button to the right of tabs: m_wndRibbonBar.AddToTabs (new CMFCRibbonButton (ID_APP_ABOUT, _T("About\na"), m_PanelImages.ExtractIcon (0))); } else { // Attach related source code to the panels for (int nCategory = 0; nCategory < m_wndRibbonBar.GetCategoryCount(); nCategory++) { CMFCRibbonCategory* pCategory = m_wndRibbonBar.GetCategory(nCategory); CString strCategory = pCategory->GetName(); if (strCategory == _T("Buttons")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_1_1 + nPanel); } } else if (strCategory == _T("Palette Buttons")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_2_1 + nPanel); } } else if (strCategory == _T("Color Buttons")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_3_1 + nPanel); } } else if (strCategory == _T("Groups")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_4_1 + nPanel); } } else if (strCategory == _T("Edit and Combo")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_5_1 + nPanel); } } else if (strCategory == _T("Other")) { for (int nPanel = 0; nPanel < pCategory->GetPanelCount(); nPanel++) { CMFCRibbonPanel* pPanel = pCategory->GetPanel(nPanel); pPanel->SetData(ID_RIBBON_SOURCE_CODE_6_1 + nPanel); } } } } return TRUE; }