爲了讓您的應用程序使用視覺樣式,你需要指定要使用ComCtl32.dll
6或更高版本,通過清單文件。 Windows隨附此文件的多個版本,因此您需要指定您需要更新版本的文件。
還要注意的是,作爲@Mgetz在評論中提到的,較新的DLL需要的Unicode正常工作,所以要確保字符集是在項目的一般屬性設置爲Unicode
。
您可以自行生成文件,或者讓Visual Studio根據源代碼中的項目依賴關係和鏈接器指令自動生成該文件。
所以,最簡單的方法是讓鏈接器生成它。打開該項目的Linker
屬性,選擇Manifest
頁面,並確保Generate Manifest
設置爲Yes
。然後將其放置在你的源代碼以下指令:
// broken into several lines for readability, as usual make sure there
// are no backspaces after trailing backslashes if copy/pasting
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
或者,您也可以手動生成清單文件。按照Enabling Visual Styles文章,它應該像這樣(的<dependency>
屬性有關的一個):
<?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="*"
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
是否缺少的[糾正清單文件(https://msdn.microsoft.com/en-us /library/windows/desktop/bb773175(v=vs.85).aspx)?檢查[MSDN提示](https://msdn.microsoft.com/en-us/library/bb773187.aspx)。 – Groo
常用控件有兩種風格,您需要選擇新控件,因爲它們只是UTF-16。所以如果你的程序是MBCS,它將無法正常工作。您需要驗證您的程序是否正確使用了Unicode,然後將相應的行添加到應用程序清單中。 – Mgetz
歡呼傢伙,它變成了鏈接器屬性,並顯示,'生成文件'屬性被設置爲'no'。你們都幫助我指出了正確的方向,因爲改變這一點解決了這個問題。 –