如何在应用程序中添加BCGControlBar的Ribbon控件

如何在应用程序中添加BCGControlBar的Ribbon控件,第1张

本文分步介绍了如何在应用程序添加BCGControlBar的Ribbon控件,并且附源码。

1、打开MainFrme.h,移除CBCGPMenuBar、 m_wndMenuBar、CBCGPToolBar、 m_wndToolBar。

2、对Ribbon Bar和主要的 Ribbon Button添加自定义。

1

2

CBCGPRibbonBar m_wndRibbonBar

CBCGPRibbonMainButton m_MainButton

3、添加定义面板图像列表。

1

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 respectively。

6、在CMainFrame::OnCreate中创建Ribbon Bar:

1

m_wndRibbonBar.Create (this)

7、初始化和设置主要的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窗体。

目前Qt没有提供这种模块或者部件,因为这是微软的专利。

微软的MFC和WPF.net都可以做。

Qt有个第三方的QTitanRibbon,但是收费的。

实际上,Ribbon界面(Office 2007风格的界面)的开发早在2008年就随着Visual C++ Feature Pack被引入到Visual Studio 2008中。在即将到来的Visual Studio 2010中,Ribbon界面的开发更是得到了原生的支持,使得Ribbon界面的开发更加简便高效。

首先,我们启动Visual Studio 2010,创建一个基于MFC的应用程序,项目模板我们选择“MFC Application”

在接下来的“MFC应用程序向导”中,我们就可以对项目的可视化风格进行选择和配置。Visual Studio 2010支持MFC风格、标准的Windows风格,Visual Studio 2005风格和Office 2007风格。而这里的Office 2007风格,就是我们要创建的Ribbon界面。

在接下来的向导页中,我们可以选择命令栏(工具栏。菜单栏)的样式,这里我们当然选择“Use a ribbon”了。当然,为了跟旧有的系统保持兼容,Visual Studio 2010也支持传统的命令式界面,如果你的用户比较保守,想继续使用传统的菜单式界面,我们可以选择“Use a menu bar and toolbar”

为了支持丰富的Office 2007界面风格,MFC默认情况下为MFC文档应用程序添加了类似Outlook风格的导航面板(Navigation pane)和标题条(Caption bar)。这两者并不是我们关注的重点,为了更好的展示Ribbon界面,我们这里就去掉这两个多余的面板。

到这里,针对新项目的设置就完成了,点击“Finish”按钮关闭应用程序向导,Visual Studio 2010就会按照我们的设置创建相应的MFC应用程序解决方案。编译运行这个解决方案,我们就得到了第一个具有Ribbon界面的应用程序。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11363660.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-15
下一篇2023-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存