How to get visual themes in a Win32 dialog created from resource files?

I have a dialog defined in the resource file. However, it uses Windows 95 style buttons, etc. How to use visual themes (i.e. Added in XP and later) for these controls?

+4
source share
1 answer

You need to embed the manifest file in an executable file that tells Windows that you want the version of the controls to include themes ( there is MSDN documentation specifically for this theme ). This is really for compatibility reasons, because some people really like to write programs that mess with the internal data structures of other programs .

In Visual C ++, perhaps the easiest way to do this is through #pragma :

 #pragma comment(linker,"/manifestdependency:\"" \ "type='win32' " \ "name='Microsoft.Windows.Common-Controls' " \ "version='6.0.0.0' " \ "processorArchitecture='*' " \ "publicKeyToken='6595b64144ccf1df' " \ "language='*'\"") 

This causes the linker to add something like this to the generated manifest file:

 <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> 

You also need to call InitCommonControlsEx() to register the appropriate management classes, or the dialog box does not appear.

As Mark Ransom pointed out in the comments below, Windows 2000 ignores manifests , so this should work on Windows 2000, Windows XP and later. In addition, some frameworks, such as MFC, define #pragma and do initialization for you.

+10
source

Source: https://habr.com/ru/post/1334028/


All Articles