1.代码
void CMainFrame::InitTabButtons() { // Add "Style" button to the right of tabs: CMFCRibbonButton* pStyleButton = new CMFCRibbonButton((UINT) -1, _T("Style\ns")); pStyleButton->SetMenu(IDR_THEME_MENU, TRUE /* Right align */); m_wndRibbonBar.AddToTabs(pStyleButton); pStyleButton = new CMFCRibbonButton((UINT)-1, _T("SXXX\ns")); m_wndRibbonBar.AddToTabs(pStyleButton); // Add "About" button to the right of tabs: m_wndRibbonBar.AddToTabs(new CMFCRibbonButton(ID_APP_ABOUT, _T("\na"), m_PanelImages.ExtractIcon(6))); }
2.代码
void CMainFrame::AddContextTab_Format() { CMFCRibbonCategory* pCategory = m_wndRibbonBar.AddContextCategory(_T("Format"), _T("Drawing tools"), ID_FORMAT_CONTEXT_TAB, /*AFX_CategoryColor_Orange*/AFX_CategoryColor_Green, 0,0);//IDB_RIBBON_FORMATSMALL, IDB_RIBBON_FORMATLARGE); pCategory->SetKeys(_T("jd")); // Create "Styles" panel CMFCRibbonPanel* pPanelStyles = pCategory->AddPanel(_T("Styles\nzs"), m_PanelImages.ExtractIcon(8)); CMFCRibbonGallery* pBtnStyles = new CMFCRibbonGallery(ID_OBJECT_STYLES, _T("Styles\nk"), 0, 0, IDB_STYLES, 40); pBtnStyles->SetIconsInRow(7); pBtnStyles->EnableMenuResize(TRUE, TRUE); pPanelStyles->Add(pBtnStyles); std::auto_ptr<CMFCRibbonColorButton> apBtnFillColor(new CMFCRibbonColorButton(ID_OBJECT_FILLCOLOR, _T("Fill Color\nsf"), FALSE, 1, -1)); apBtnFillColor->SetDefaultCommand(FALSE); apBtnFillColor->EnableAutomaticButton(_T("&Automatic"), RGB(128, 128, 128)); apBtnFillColor->EnableOtherButton(_T("&More Fill Colors..."), _T("More Fill Colors")); apBtnFillColor->SetColumns(10); apBtnFillColor->SetColorBoxSize(CSize(17, 17)); apBtnFillColor->AddColorsGroup(_T("Theme Colors"), m_lstMainColors); apBtnFillColor->AddColorsGroup(_T(""), m_lstAdditionalColors, TRUE); apBtnFillColor->AddColorsGroup(_T("Standard Colors"), m_lstStandardColors); apBtnFillColor->AddSubItem(new CMFCRibbonButton(ID_OBJECT_NOFILL, _T("&No Fill\nn"), 2)); apBtnFillColor->SetColor((COLORREF)-1); pPanelStyles->Add(apBtnFillColor.release()); std::auto_ptr<CMFCRibbonColorButton> apBtnLineColor(new CMFCRibbonColorButton(ID_OBJECT_LINECOLOR, _T("Line Color\nso"), FALSE, 3, -1)); apBtnLineColor->SetDefaultCommand(FALSE); apBtnLineColor->EnableAutomaticButton(_T("&Automatic"), RGB(0, 0, 0)); apBtnLineColor->EnableOtherButton(_T("&More Line Colors..."), _T("More Line Colors")); apBtnLineColor->SetColumns(10); apBtnLineColor->SetColorBoxSize(CSize(17, 17)); apBtnLineColor->AddColorsGroup(_T("Theme Colors"), m_lstMainColors); apBtnLineColor->AddColorsGroup(_T(""), m_lstAdditionalColors, TRUE); apBtnLineColor->AddColorsGroup(_T("Standard Colors"), m_lstStandardColors); apBtnLineColor->AddSubItem(new CMFCRibbonButton(ID_OBJECT_NOLINE, _T("&No Line\nn"), 2)); apBtnLineColor->SetColor((COLORREF)-1); pPanelStyles->Add(apBtnLineColor.release()); CStringArray sa; sa.Add(_T("1 pt")); sa.Add(_T("2 pt")); sa.Add(_T("3 pt")); sa.Add(_T("4 pt")); sa.Add(_T("5 pt")); sa.Add(_T("6 pt")); sa.Add(_T("7 pt")); std::auto_ptr<CRibbonListButton> apBtnLineWeight(new CRibbonListButton(ID_OBJECT_LINEWEIGHT, _T("Line Weight\nsw"), 4, -1, IDB_LINEWEIGHT, 96, sa)); apBtnLineWeight->AddSubItem(new CMFCRibbonButton(ID_OBJECT_LINEWEIGHT_MORE, _T("More &Lines..."), 5, -1)); apBtnLineWeight->EnableMenuResize(TRUE, TRUE); // Vertical only pPanelStyles->Add(apBtnLineWeight.release()); #ifdef ENABLE_RIBBON_LAUNCH_BUTTON pPanelStyles->EnableLaunchButton(ID_OBJECT_PROPERTIES, 6, _T("fa")); #endif // ENABLE_RIBBON_LAUNCH_BUTTON // Create "Arrange" panel CMFCRibbonPanel* pPanelArrange = pCategory->AddPanel(_T("Arrange\nzj"), m_PanelImages.ExtractIcon(3)); pPanelArrange->Add(new CMFCRibbonButton(ID_OBJECT_MOVETOFRONT, _T("Move to Front\nmf"), 7, 1)); pPanelArrange->Add(new CMFCRibbonButton(ID_OBJECT_MOVEFORWARD, _T("Move Forward\nmw"), 9, 3)); pPanelArrange->Add(new CMFCRibbonButton(ID_OBJECT_MOVEBACK, _T("Move Backward\nmd"), 10, 4)); pPanelArrange->Add(new CMFCRibbonButton(ID_OBJECT_MOVETOBACK, _T("Move to Back\nmb"), 8, 2)); }