1. 程式人生 > 其它 >解決 Win32 系統控制元件都是老式的問題

解決 Win32 系統控制元件都是老式的問題

將下列程式碼加入標頭檔案頂部即可:

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

 簡單來說,你看到的大部分 Win32 視窗方框都是由公共控制元件庫(Common Control Library) Comctl32.dll 實現的視窗。要使應用程式能夠顯示出與作業系統版本匹配的視覺樣式,必須使用ComCtl32.dll 版本 6.0 或更高版本;但在沒有任何定義的預設情況下,應用程式使用 User32.dll 中定義的使用者控制元件(User Controls)和 ComCtl32.dll 版本 5.0 中定義的公共控制元件(Common Controls)。如果要求指定應用程式使用 ComCtl32.dll 版本 6.0 或更高,則必須新增應用程式清單(manifest,如其他答主所述)或編譯器指令(#pragma)使得使應用程式能夠指定它需要的程式集(Assembly,一組由不同版本 dll 組成的物件列表)版本。

具體可參考官方文件 Enabling Visual Styles

ComCtl32.dll 版本 6.0 不可再發行(redistributable),也就是說只有當應用程式在對應的 Windows 版本上執行時,這些對應的樣式效果可用,也就是說你不能在 Windows 11 上編譯程式之後拿到 Windows XP 上執行,要求其用這種方法顯示 Windows 11 的效果。關於不同作業系統內建的對應版本:[2]

Version Distribution Platform
5.81 Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6
5.82 Windows Server 2003
Windows Vista
Windows Server 2008
Windows 7
6.0 Windows Server 2003
6.10 Windows Vista
Windows Server 2008
Windows 7

宣告

原文連結:https://www.zhihu.com/question/489914730