为了在应用程序中启用Backstage视图,您可以执行以下步骤。以下的指南假设Ribbon控件被定义为m_wndRibbonBar,应用程序按钮上显示的文本是"File",命令图片以图片列表的形式展示,视图项拥有一个资源ID IDB_FILESMALL。下面提到的图像索引假设您已经获得下面的图像列表:
1. 使用Application Wizard或一个现有的基于Ribbon的应用程序生成一个基于Ribbon的应用程序。
2. 为您的应用程序启用Backstage视图,对于某些可视化管理器,您可以使其适用于所有状况。最佳位置是OnAppLook处理器,您可以调用m_wndRibbonBar.SetBackstageMode (bCondition);
3. 您可以使用以下代码设置应用程序按钮颜色:
1
2
|
COLORREF
clr = RGB(0, 0, 192);
CBCGPVisualManager::GetInstance()->;SetMainButtonColor (clr);
|
如果您想开发一个套包,那么可以通过应用程序按钮的颜色来区分每个应用程序。
4. 找到您初始化应用程序菜单的位置(主目录)。
5. 如果您想使用Backstage视图替换应用程序菜单,那么可以删除Application Button/Application Menu的所有颜色。
6. 如果您想Backstage视图显示仅适用于可视化管理器(基于其他条件),在主目录初始化之后新增Backstage视图的初始化。
7. 新增Backstage视图到Ribbon Bar中:
1
|
CBCGPRibbonBackstageViewPanel* pBackstagePanel = m_wndRibbonBar.AddBackstageCategory(_T(
"File"
), IDB_RIBBON_FILESMALL);
|
该方法返回一个指针到CBCGPRibbonBackstageViewPanel,它代表Backstage视图用于后续调用,这将增加命令并查看条目。
8. 使用步骤7中获得的指针添加如下命令:
1
2
3
4
5
|
pBackstagePanel->AddCommand (ID_FILE_SAVE, _T(
"Save"
), 2
/* Image index */
);
pBackstagePanel->Command (ID_FILE_SAVE_AS, _T(
"Save As"
), 3
/* Image index */
);
pBackstagePanel->AddCommand (ID_FILE_NEW, _T(
"New"
), 0
/* Image index */
);
pBackstagePanel->AddCommand (ID_FILE_OPEN, _T(
"Open"
), 1
/* Image index */
);
pBackstagePanel->AddCommand (ID_FILE_CLOSE, _T(
"Close"
), 4
/* Image index */
);
|
当第6步完成之后,您的Backstage视图使用步骤5中的保存,另存为,新建,打开和关闭进行初始化,同时显示来自IDB_FILESMALL图像列表中的图像位于索引2,3,0,1和4。
9. 现在您可以编译应用程序,打开Backstage视图,看到左侧的五个命令:
10. 现在添加一个基于子对话框的视图,这将显示MRU文件列表。
有兴趣的朋友可以点击查看更多BCG资源>>