开启程序的Visual Styles
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了开启程序的Visual Styles相关的知识,希望对你有一定的参考价值。
首先看看MS对Visual Styles的解释:
Windows XP and later operating systems support a feature called visual styles that enables the appearance of common controls to change based on the theme chosen by the user. Prior to Windows 8, you must specifically configure your application to use visual styles; otherwise, the application‘s common controls are always rendered in the style associated with the Windows Classic theme, regardless of the currently selected theme. In Windows 8, visual styles can‘t be turned off, Windows Classic mode no longer exists, and high contrast mode has been modified to work with visual styles.
XP以后的系统支持一种叫做可视化风格的界面,界面可以随着系统的主题改变而变化。程序必须明确的去启用这种风格,否则程序就是经典风格界面 ,程序界面不随系统主题而改变。win8还新增了一种高对比度模式的界面,暂不讨论。
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773187(v=vs.85).aspx
可以明显感觉visual styles要圆润漂亮了很多
开启 Visual Styles的方法
要使用 Visual Styles,需要第六版或更新的的ComCtl32.dll, ComCtl32.dll不重发行,只是预置在系统当中。xp以后的系列都同时有第五版和第六版的
ComCtl32.dll,第六版的ComCtl32.dll包含user controls and the common controls。默认情况下程序使用定义在User32.dll中的user controls 和定义在第五版 ComCtl32.dll 中的 common controls
comCtl32.dll版本介绍
ComCtl32.dll | |
---|---|
Version | Distribution Platform |
4.0 | Windows 95 and Microsoft Windows NT 4.0 |
4.70 | Internet Explorer 3.0 |
4.71 | Microsoft Internet Explorer 4.0 |
4.72 | Microsoft Internet Explorer 4.01 and Windows 98 |
5.80 | Windows 98 Second Edition and Microsoft Internet Explorer 5 |
5.81 | Windows Millennium Edition (Windows Me), Windows 2000, Microsoft Internet Explorer 5.01, Microsoft Internet Explorer 5.5, and Microsoft Internet Explorer 6 |
5.82 | Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, and Windows 7 |
6.0 | Windows XP, Windows Server 2003 |
6.10 | Windows Vista, Windows Server 2008, and Windows 7 |
http://msdn.microsoft.com/en-us/library/windows/desktop/hh298349(v=vs.85).aspx
@:添加程序清单的方法1
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <assemblyIdentity
- version="1.0.0.0"
- processorArchitecture="*"
- name="CompanyName.ProductName.YourApplication"
- type="win32"
- />
- <description>Your application description here.</description>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity
- type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0"
- processorArchitecture="*"
- publicKeyToken="6595b64144ccf1df"
- language="*"
- />
- </dependentAssembly>
- </dependency>
- </assembly>
Attribute | Description |
---|---|
version | Version of the manifest. The version must be in the form major.minor.revision.build (that is, n.n.n.n, where n <=65535). |
processorArchitecture | Processor for which your application is developed. |
name | Includes company name, product name and application name. |
type | Type of your application, such as Win32. |
dependency段 assemblyIdentity 元素的属性集
Attribute | Description |
---|---|
type | Type of the dependency component, such as Win32. |
name | Name of the component. |
version | Version of the component. |
processorArchitecture | Processor that the component is designed for.指定处理器。有效值为 msil、x86、IA64 和 amd64。 |
publicKeyToken | Key token used with this component. |
language | Language of the component. |
@:添加程序清单的方法2
在vs2005以后,设置visual styles可以不需要程序部署清单文件,而只是发送一个编译指令。在“stdafx.h”中添加一下几行就可以了
- #pragma comment(linker,"\"/manifestdependency:type=‘win32‘ \
- name=‘Microsoft.Windows.Common-Controls‘ version=‘6.0.0.0‘ \
- processorArchitecture=‘*‘ publicKeyToken=‘6595b64144ccf1df‘ language=‘*‘\"")
MSND上说还需
- <span style="white-space:pre"> </span>// 如果一个运行在 Windows XP 上的应用程序清单指定要
- // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
- //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
- INITCOMMONCONTROLSEX InitCtrls;
- InitCtrls.dwSize = sizeof(InitCtrls);
- // 将它设置为包括所有要在应用程序中使用的
- // 公共控件类。
- InitCtrls.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&InitCtrls);
但是发现不添加也没事,xp也可正常实现,懂得可以给说说
@:关闭Visual Styles
- #include "Uxtheme.h"
- #pragma comment(lib,"UxTheme.lib")
- SetWindowTheme(hwnd, L" ", L" ");
- #include "Uxtheme.h"
- #pragma comment(lib,"UxTheme.lib")
- DWORD dwFlags = (STAP_ALLOW_CONTROLS | STAP_ALLOW_WEBCONTENT);
- SetThemeAppProperties(dwFlags);
http://blog.csdn.net/x356982611/article/details/18403869
以上是关于开启程序的Visual Styles的主要内容,如果未能解决你的问题,请参考以下文章
新的Visual-Studio项目的默认应用程序兼容性清单?
是否有 GetThemeColor / Visual Styles API 的有效参数组合列表
Visual Studio 2017离线安装失败:安装程序清单签名验证失败
是否可以使用 Visual Studio 6.0(VC98 编译器)构建使用清单指定依赖关系的应用程序?