開啓程序的Visual Styles

首先看看MS對Visual Styles的解釋:html

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.windows

XP之後的系統支持一種叫作可視化風格的界面,界面能夠隨着系統的主題改變而變化。程序必須明確的去啓用這種風格,不然程序就是經典風格界面 ,程序界面不隨系統主題而改變。win8還新增了一種高對比度模式的界面,暫不討論。app

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773187(v=vs.85).aspxless

能夠明顯感受visual styles要圓潤漂亮了不少函數

 

開啓 Visual Styles的方法ui

 

要使用 Visual Styles,須要第六版或更新的的ComCtl32.dll, ComCtl32.dll不重發行,只是預置在系統當中。xp之後的系列都同時有第五版和第六版的this

ComCtl32.dll,第六版的ComCtl32.dll包含user controls and the common controls。默認狀況下程序使用定義在User32.dll中的user controls  和定義在第五版 ComCtl32.dll 中的 common controlsspa

 

comCtl32.dll版本介紹.net

 

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).aspxcode

 

 

@:添加程序清單的方法1

在工程目錄下新建一個文本xml格式的清單文件「程序名.exe.manifest」,而後添加到資源中,文件內容爲
 
[html]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">  
  3. <assemblyIdentity  
  4.     version="1.0.0.0"  
  5.     processorArchitecture="*"  
  6.     name="CompanyName.ProductName.YourApplication"  
  7.     type="win32"  
  8. />  
  9. <description>Your application description here.</description>  
  10. <dependency>  
  11.     <dependentAssembly>  
  12.         <assemblyIdentity  
  13.             type="win32"  
  14.             name="Microsoft.Windows.Common-Controls"  
  15.             version="6.0.0.0"  
  16.             processorArchitecture="*"  
  17.             publicKeyToken="6595b64144ccf1df"  
  18.             language="*"  
  19.         />  
  20.     </dependentAssembly>  
  21. </dependency>  
  22. </assembly>  


mainfest詳解:
 
description段 assemblyIdentity 元素的屬性集
 
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、x8六、IA64 和 amd64。
publicKeyToken Key token used with this component.
language Language of the component.

 

 

@:添加程序清單的方法2

 

在vs2005之後,設置visual styles能夠不須要程序部署清單文件,而只是發送一個編譯指令。在「stdafx.h」中添加一下幾行就能夠了

 

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. #pragma comment(linker,"\"/manifestdependency:type='win32' \  
  2. name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \  
  3. processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")  

 

MSND上說還需

 

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. <span style="white-space:pre">  </span>// 若是一個運行在 Windows XP 上的應用程序清單指定要  
  2.     // 使用 ComCtl32.dll 版本 6 或更高版原本啓用可視化方式,  
  3.     //則須要 InitCommonControlsEx()。不然,將沒法建立窗口。  
  4.     INITCOMMONCONTROLSEX InitCtrls;  
  5.     InitCtrls.dwSize = sizeof(InitCtrls);  
  6.     // 將它設置爲包括全部要在應用程序中使用的  
  7.     // 公共控件類。  
  8.     InitCtrls.dwICC = ICC_WIN95_CLASSES;  
  9.     InitCommonControlsEx(&InitCtrls);  

 

 

 

可是發現不添加也沒事,xp也可正常實現,懂得能夠給說說

 

 

 

@:關閉Visual Styles

1:能夠調用SetWindowTheme函數關閉一個或多個控件的visual styles
[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. #include "Uxtheme.h"  
  2. #pragma comment(lib,"UxTheme.lib")  
 
[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. SetWindowTheme(hwnd, L" ", L" ");  
 
2:也能夠調用InitInstance以前調用void SetThemeAppProperties( DWORD dwFlags),不設置 STAP_ALLOW_NONCLIENT 標誌可關閉整個程序全部窗口的的Visual Styles
 
[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. #include "Uxtheme.h"  
  2. #pragma comment(lib,"UxTheme.lib")  

[cpp]  view plain  copy
 
 在CODE上查看代碼片派生到個人代碼片
  1. DWORD dwFlags = (STAP_ALLOW_CONTROLS | STAP_ALLOW_WEBCONTENT);  
  2. SetThemeAppProperties(dwFlags);  

http://blog.csdn.net/x356982611/article/details/18403869

相關文章
相關標籤/搜索