有兩種方法可以使vc6或者vc2003編譯出來的MFC程式具有XP的風格,當然這需要在Windows XP系統下運行。
方法一,使用外置的manifest描述檔案
在exe檔案所在目錄中建立一個同名的.manifest檔案。假設你有一個可執行檔app1.exe,則建立app1.exe.manifest。注意該檔案的檔案名稱是在exe的完整檔案名稱後加.manifest。該檔案的內容如下:
Code:
<?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="X86"
name="Microsoft.Windows.dummy"
type="win32"
/>
<description>Your app description here</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
方法二,使用內建的manifest描述檔案
這種方法可以將manifest檔案編譯到exe檔案當中,發布的時候不需要額外增加一個.manifest檔案。
步驟如下:
首先,在程式的RES目錄下建一個檔案,命名xp.manifest,檔案內容為:
Code:
<?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="X86"
name="Microsoft.Windows.dummy"
type="win32"
/>
<description>Your app description here</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
然後,在VC中匯入資源,匯入xp.manifest,類型為24,並且修改ID為IDR_MANIFEST。
最後,通過菜單View-Resources Symbol …或者直接修改resource.h,將IDR_MANIFEST的值改為1。
編譯後運行,程式就有xp的風格了。
PS:這裡我再多解釋一下,“1”代表資源ID,必須是“1”。“24”代表資源類型,我想我們對RT_ACCELERATOR、RT_BITMAP、RT_MENU、RT_STRING等資源都非常熟悉,而“24”實際上是RT_MANIFEST。