I've got a dialog defined in a resource file. However, it's using the Windows 95 style buttons and such. How do I use visual themes (i.e. those added in XP and later) for these controls?
You create a modal dialog box by using the DialogBox function. You must specify the identifier or name of a dialog box template resource and a pointer to the dialog box procedure. The DialogBox function loads the template, displays the dialog box, and processes all user input until the user closes the dialog box.
The Visual Studio resource editors do not support editing embedded resources. The term resource file can refer to any of several file types, such as: The resource script ( . rc ) file of a program.
A dialog box is a temporary window an application creates to retrieve user input. An application typically uses dialog boxes to prompt the user for additional information for menu items.
You need to embed a manifest file into the executable that tells Windows you want the version of the controls that have themes enabled (there's MSDN documentation specifically for this topic). This is really for compatibility reasons because some people really like to write programs that mess around with the internal data structures of other programs.
In Visual C++, probably the easiest way to do this is via a #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 control classes, or the dialog box won't appear.
As Mark Ransom has mentioned in the comments below, Windows 2000 ignores theming manifests, so this should still work in Windows 2000, Windows XP and later. Also, some frameworks like MFC define the #pragma
and performs the initialization for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With