文档彩票走势图>>BCGControlBar使用教程>>BCGControlBar中文教程:Ribbon Bar(2/3)
BCGControlBar中文教程:Ribbon Bar(2/3)
如何在您的应用程序中添加ribbon控件
1. 打开MainFrme.h,删除CBCGPMenuBar m_wndMenuBar和CBCGPToolBar m_wndToolBar。
2. 为Ribbon Bar和Ribbon Main Button新增定义:
CBCGPRibbonBar m_wndRibbonBar; CBCGPRibbonMainButton m_MainButton;
3. 为面板图像列表新增定义:
CBCGPToolBarImages m_PanelIcons;
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:
m_wndRibbonBar.Create (this);
7. 初始化并设置Main Ribbon Button:
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. 初始化并加载面板图标的图像列表:
m_PanelIcons.SetImageSize (CSize (16, 16)); m_PanelIcons.Load (IDB_PANEL_ICONS);
9. 添加第一个类别:
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. 添加第一个面板到类别中:
CBCGPRibbonPanel* pPanel = pCategory->AddPanel ( _T("Clipboard"), // Panel name m_PanelIcons.ExtractIcon (0)); // Panel icon
11. 现在,我们需要添加ribbon元素(按钮)到面板中:
// 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。