工控编程吧

标题: MFC扩展库BCGP外观主题管理设置 [打印本页]

作者: qq263946146    时间: 2019-12-26 15:05
标题: MFC扩展库BCGP外观主题管理设置
入门使用教程已在下面帖子分享:
https://www.gkbc8.com/forum.php?mod=viewthread&tid=15055
这里我们来看下默认程序的外观主题是如何管理与设置的。

我们创建一个基于BCGP单文档应用程序后,在APP类的构造函数中会有一系列AddVisualTheme函数调用。
目的就是添加全局的程序外观主题,BCGP默认自带约30个主题。
可以在用户手册查找函数AddVisualTheme找到相关介绍,如下:
void CBCGPWinApp::AddVisualTheme  ( BCGP_VISUAL_THEME  theme, UINT  nCommandID,
BOOL  bActive = FALSE, CRuntimeClass *  pRTICustom = NULL )
其中BCGP_VISUAL_THEME  为枚举类型。
enum CBCGPWinApp::BCGP_VISUAL_THEME
BCGP_VISUAL_THEME_DEFAULT Windows native theme, default.
BCGP_VISUAL_THEME_OFFICE_2000 Office 2000-style theme.
BCGP_VISUAL_THEME_OFFICE_XP Office XP/Visual Studio 2003.NET-style theme.
BCGP_VISUAL_THEME_OFFICE_2003 Office 2003-style theme.
BCGP_VISUAL_THEME_VS_2005 Visual Studio 2005-style theme.
BCGP_VISUAL_THEME_OFFICE_2007_BLUE Office 2007-style theme, blue color.
BCGP_VISUAL_THEME_OFFICE_2007_BLACK Office 2007-style theme, black color.
BCGP_VISUAL_THEME_OFFICE_2007_SILVER Office 2007-style theme, silver color.
BCGP_VISUAL_THEME_OFFICE_2007_AQUA Office 2007-style theme, aqua color.
BCGP_VISUAL_THEME_CARBON Carbon theme.
BCGP_VISUAL_THEME_VS_2008 Visual Studio 2008-style theme.
BCGP_VISUAL_THEME_VS_2010 Visual Studio 2010-style theme.
BCGP_VISUAL_THEME_SCENIC Windows 7/8/10-style theme.
BCGP_VISUAL_THEME_OFFICE_2010_BLUE Office 2010-style theme, blue color.
BCGP_VISUAL_THEME_OFFICE_2010_BLACK Office 2010-style theme, black color.
BCGP_VISUAL_THEME_OFFICE_2010_SILVER Office 2010-style theme, silver color.
BCGP_VISUAL_THEME_VS_2012_LIGHT Visual Studio 2012-style theme, light color.
BCGP_VISUAL_THEME_VS_2012_DARK Visual Studio 2012-style theme, dark color.
BCGP_VISUAL_THEME_VS_2012_BLUE Visual Studio 2012-style theme, blue color.
BCGP_VISUAL_THEME_OFFICE_2013_WHITE Office 2013-style theme, white color.
BCGP_VISUAL_THEME_OFFICE_2013_GRAY Office 2013-style theme, light-gray color.
BCGP_VISUAL_THEME_OFFICE_2013_DARK_GRAY Office 2013-style theme, dark-gray color.
BCGP_VISUAL_THEME_VS_2013_LIGHT Visual Studio 2013/2015-style theme, light color.
BCGP_VISUAL_THEME_VS_2013_DARK Visual Studio 2013/2015-style theme, dark color.
BCGP_VISUAL_THEME_VS_2013_BLUE Visual Studio 2013/2015-style theme, blue color.
BCGP_VISUAL_THEME_OFFICE_2016_COLORFUL Office 2016-style theme, colorful.
BCGP_VISUAL_THEME_OFFICE_2016_DARK_GRAY Office 2016-style theme, dark gray color.
BCGP_VISUAL_THEME_OFFICE_2016_WHITE Office 2016-style theme, white color.
BCGP_VISUAL_THEME_OFFICE_2016_BLACK Office 2016-style theme, black color.
BCGP_VISUAL_THEME_CUSTOM Custom theme.
BCGP_VISUAL_THEME_CUSTOM 不包含共29种外观。
所以在APP类中我们可以调用函数29次,添加29种默认自带的外观风格。
然后再调用函数SetVisualTheme,设置哪种风格生效。
函数AddVisualTheme  参数1为枚举类型,参数2为我们定义的指令ID。
我们可以在菜单栏上分别添加29个菜单项,设置对应ID如ID_VIEW_APPLOOK_CARBON,
这样在程序运行时,点击菜单对应的切换外观按钮,就可以切换不同风格。
如帖子例程,在APP类构造函数中添加了全部风格。
  1. CMy111App::CMy111App()
  2. {
  3.         CBCGPVisualManagerVS2012::m_bAutoGrayscaleImages = FALSE;

  4.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2000, ID_VIEW_APPLOOK_2000);
  5.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_XP, ID_VIEW_APPLOOK_XP);
  6.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2003, ID_VIEW_APPLOOK_2003);
  7.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2005, ID_VIEW_APPLOOK_VS2005);
  8.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2008, ID_VIEW_APPLOOK_VS2008);
  9.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2010, ID_VIEW_APPLOOK_VS2010);
  10.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2013_LIGHT, ID_VIEW_APPLOOK_VS2017_LIGHT);
  11.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2013_DARK, ID_VIEW_APPLOOK_VS2017_DARK);
  12.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2013_BLUE, ID_VIEW_APPLOOK_VS2017_BLUE);
  13.         AddVisualTheme(BCGP_VISUAL_THEME_DEFAULT, ID_VIEW_APPLOOK_WINDOWS_NATIVE);
  14.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2007_BLUE, ID_VIEW_APPLOOK_2007);
  15.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2007_BLACK, ID_VIEW_APPLOOK_2007_1);
  16.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2007_SILVER, ID_VIEW_APPLOOK_2007_2);
  17.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2007_AQUA, ID_VIEW_APPLOOK_2007_3);
  18.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2010_BLUE, ID_VIEW_APPLOOK_2010_1);
  19.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2010_BLACK, ID_VIEW_APPLOOK_2010_2);
  20.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2010_SILVER, ID_VIEW_APPLOOK_2010_3);
  21.         AddVisualTheme(BCGP_VISUAL_THEME_SCENIC, ID_VIEW_APPLOOK_SCENIC);
  22.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2013_WHITE, ID_VIEW_APPLOOK_2013_1);
  23.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2013_GRAY, ID_VIEW_APPLOOK_2013_2);
  24.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2013_DARK_GRAY, ID_VIEW_APPLOOK_2013_3);
  25.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2016_COLORFUL, ID_VIEW_APPLOOK_2016_1);
  26.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2016_DARK_GRAY, ID_VIEW_APPLOOK_2016_2);
  27.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2016_WHITE, ID_VIEW_APPLOOK_2016_3);
  28.         AddVisualTheme(BCGP_VISUAL_THEME_OFFICE_2016_BLACK, ID_VIEW_APPLOOK_2016_4);
  29.         //
  30.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2012_LIGHT, ID_VIEW_APPLOOK_2012_1);
  31.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2012_DARK, ID_VIEW_APPLOOK_2012_2);
  32.         AddVisualTheme(BCGP_VISUAL_THEME_VS_2012_BLUE, ID_VIEW_APPLOOK_2012_3);
  33.         AddVisualTheme(BCGP_VISUAL_THEME_CARBON, ID_VIEW_APPLOOK_CARBON);
  34.         SetVisualTheme(BCGP_VISUAL_THEME_VS_2013_BLUE);
复制代码
并在默认主菜单资源中添加了对应的菜单项。
(, 下载次数: 1)