Windows XP 引入視覺樣式 (Visual Styles),預設編譯的 VC6.0 應用程式會顯示經典 95/98 風格控制項。啟用 XP 風格只需在專案資源中嵌入 Side-by-Side 組件資訊清單,宣告相依於 Common Controls 6.0 版本。
24 (對應 RT_MANIFEST)。在資源編輯器中貼入以下 XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
processorArchitecture="x86"
version="5.1.0.0"
type="win32"
name="test.exe"/>
<description>Test Application</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="x86"/>
</dependentAssembly>
</dependency>
</assembly>
關鍵欄位說明:
name:設為您的執行檔名稱 (如 MyApp.exe)。version:應用程式版本號。Microsoft.Windows.Common-Controls version 6.0.0.0:啟用 ComCtl32 v6 (XP 風格)。1 (對應 CREATEPROCESS_MANIFEST_RESOURCE_ID)。stdafx.h 或原始檔包含 <commctrl.h>,並連結 comctl32.lib。執行 Rebuild All,程式即會在 XP 及更新系統顯示視覺樣式按鈕、編輯框、進度條等控制項。
Windows XP 以降,系統載入器檢查執行檔資源區段是否包含 ID=1、Type=24 (RT_MANIFEST) 的資源。若存在且宣告相依 Microsoft.Windows.Common-Controls v6,載入器會載入 comctl32.dll 6.0 版 (位於 WinSxS 目錄),提供主題化控制項渲染。VC6.0 預設連結舊版 ComCtl32,嵌入資訊清單即可重導向至新版。
mt.exe (Windows SDK) 檢視內嵌資訊清單:mt.exe -inputresource:MyApp.exe;#1 -out:manifest.xml。| 現象 | 原因與解決 |
|---|---|
| 仍顯示經典風格 | 資源 ID 不為 1、XML 格式錯誤、未 Rebuild、系統非 XP/更新版本。 |
| 應用程式無法啟動 (Side-by-Side 錯誤) | 資訊清單 XML 語法錯誤、版本號不存在、publicKeyToken 錯誤。使用事件檢視器查看詳細錯誤碼。 |
| 部分控制項未主題化 | 自繪控制項、舊版 ActiveX、未呼叫 InitCommonControlsEx (Win32 專案需確認)。 |
嵌入資訊清單資源是讓 VC6.0 應用程式在支援視覺樣式的 Windows 版本 (XP 至 11) 正確呈現現代化介面的最簡單、標準做法。無需修改程式碼、無需外部 Manifest 檔案,僅需幾步資源編輯即可完成。