Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get visual themes on Win32 dialogs generated from resource files?

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?

like image 480
Billy ONeal Avatar asked Jan 03 '11 04:01

Billy ONeal


People also ask

How do I create a dialog box in win32?

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.

What are RC files in Visual Studio?

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.

What is the use of use dialogue box?

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.


1 Answers

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.

like image 185
In silico Avatar answered Sep 23 '22 14:09

In silico