引用地址:http://hi.baidu.com/linyuanyumeng/blog/item/791c359575646f047bf48022.htmlXP風格就是通過給控制項加一些特效(例如:邊界圓角化)達到美化介面的效果。
XP風格的UI效果是由Microsoft.Windows.Common-Controls提供的一種實現,為了擁有這種效果,你需要讓你的程式依賴於Microsoft.Windows.Common-Controls這個組件。微軟提供了Manifest來讓讓我們聲明這種依賴。
★★★方法一
在Win32程式中預設沒有使用Windows XP的視覺風格
如果你使用的是Visual Studio 2005以後的版本VS,
只需要在stdafx.h中加入以下代碼即可:
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
MFC中預設是使用了視覺樣式的,不過它用的以下代碼:
01) #ifdef _UNICODE
02) #if defined _M_IX86
03) #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
04) #elif defined _M_IA64
05) #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
06) #elif defined _M_X64
07) #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
08) #else
09) #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' " "version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
10) #endif
11) #endif
如果你的項目是ANSI,可以把第一行的#ifdef _UNICODE和最後一行的#endif去掉就可以了。
編譯後產生一個與程式同名副檔名為.manifest的檔案內容如下所示
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*' />
</dependentAssembly>
</dependency>
</assembly>
★★★方法二
1)在程式的.rc檔案中定義下面這一行(EXE中)
1 RT_MANIFEST "XPstyle.manifest"
若為DLL中則定義為
2 RT_MANIFEST "XPstyle.manifest"
2)將下面的內容儲存為XPstyle.manifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
name="XP style manifest"
processorArchitecture="x86"
version="1.0.0.0"
type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>
3)編譯.rc檔案,最終以上資訊會隨資源檔一起嵌入程式檔案中
+++++++++++++++++++MSDN 引申+++++++++++++++++++++++++++
How to: Embed a Manifest Inside a C/C++ Application
Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies
About Manifest Tool(mt.exe)
可以使用手工編譯mainfest檔案到exe中,使用mt工具進行編譯,mt.exe如果是vs2005則要使用相應的sdk(可以使用最新的SDK)中mt.exe替換原安裝程式中的mt.exe