BCGControlBar Pro for MFC最新試用版下載請猛戳>>>html
如何在您的應用程序中添加ribbon控件
1. 打開MainFrme.h,刪除CBCGPMenuBar m_wndMenuBar和CBCGPToolBar m_wndToolBar。this
2. 爲Ribbon Bar和Ribbon Main Button新增定義:spa
1code 2htm |
CBCGPRibbonBar m_wndRibbonBar; 教程 CBCGPRibbonMainButton m_MainButton; ip |
3. 爲面板圖像列表新增定義:ci
1資源 |
CBCGPToolBarImages m_PanelIcons; get |
4. 打開MainFrm.cpp,而後刪除與m_wndMenuBar和m_wndToolBar相關的全部東西。
5. 爲Ribbon Main Button (IDB_MAIN)新增資源位圖,使用的位圖像素爲26x26。爲小圖標圖像列表(高度16像素)和大圖標圖像列表(高度32像素)新增位圖。將它們分別命名爲IDB_SMALL_ICONS和IDB_LARGE_ICONS。
6. 在CMainFrame::OnCreate中建立Ribbon Bar:
1 |
m_wndRibbonBar.Create ( this ); |
7. 初始化並設置Main Ribbon Button:
1 2 3 4 |
m_MainButton.SetMenu (IDR_FILE_MENU); m_MainButton.SetImage (IDB_MAIN); m_MainButton.SetToolTipText (_T( "File" )); m_wndRibbonBar.SetMainButton (&m_MainButton, CSize (45, 45)); |
8. 初始化並加載面板圖標的圖像列表:
1 2 |
m_PanelIcons.SetImageSize (CSize (16, 16)); m_PanelIcons.Load (IDB_PANEL_ICONS); |
9. 添加第一個類別:
1 2 3 4 |
CBCGPRibbonCategory* pCategory = m_wndRibbonBar.AddCategory (_T( "&Write" ), // Category name IDB_WRITE, // Category small images (16 x 16) IDB_WRITE_LARGE); // Category large images (32 x 32) |
10. 添加第一個面板到類別中:
1 2 3 |
CBCGPRibbonPanel* pPanel = pCategory->AddPanel ( _T( "Clipboard" ), // Panel name m_PanelIcons.ExtractIcon (0)); // Panel icon |
11. 如今,咱們須要添加ribbon元素(按鈕)到面板中:
1 2 3 4 5 6 7 8 9 10 11 12 |
// Create the first button to Panel ("Paste"): CBCGPRibbonButton* pPasteButton = new CBCGPRibbonButton (ID_EDIT_PASTE, _T( "Paste" ), -1, 0); // The third parameter (-1) tells that this button does not have a small icon. // Therefore the "Paste" button will be always displayed with large icon. // Associate a popup menu with the "Paste" button: pPasteButton->SetMenu (IDR_CONTEXT_MENU); // Add other buttons to the panel. These buttons have small icons only: pPanel->Add ( new CBCGPRibbonButton (ID_EDIT_CUT, _T( "Cut" ), 1)); pPanel->Add ( new CBCGPRibbonButton (ID_EDIT_COPY, _T( "Copy" ), 2)); pPanel->Add ( new CBCGPRibbonButton (ID_EDIT_PAINT, _T( "Paint" ), 9)); |
這樣,您就能夠設置ribbon bar。
有興趣的朋友能夠點擊查看更多教程>>