Question

Some of the controls I've created seem to default to the old Windows 95 theme, how do I prevent this? Here's an example of a button that does not retain the Operating System's native appearance (I'm using Vista as my development environment):

HWND button = CreateWindowEx(NULL, L"BUTTON", L"OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                  170, 340, 80, 25, hwnd, NULL, GetModuleHandle(NULL), NULL);

I'm using native C++ with the Windows API, no managed code.

Was it helpful?

Solution

I believe it has got nothing to do with your code, but you need to set up a proper manifest file to get the themed controls.

Some info here: @msdn.com and here: @blogs.msdn.com

You can see a difference between application with and without manifest here: heaventools.com

OTHER TIPS

To add a manifest to the application you need create a MyApp.manifest file and add it to the application resource file:

//-- This define is normally part of the SDK but define it if this 
//-- is an older version of the SDK.
#ifndef RT_MANIFEST
#define RT_MANIFEST              24
#endif

//-- Add the MyApp XP Manifest file
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyApp.manifest"

With newer versions of Visual Studio there is a Manifest Tool tab found in the project settings and the Additional Manifest Files field found on this tab can also be used to define the manifest file.

Here is a simple MyApp.manifest file for a Win32 application:

<?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.1"
    processorArchitecture="X86"
    name="Microsoft.Windows.MyApp"
    type="win32"
/>
<description>MyApp</description>
</assembly>

If you application depends on the other dlls these details can also be added to the manifest and Windows will use this information to make sure your application always uses the correct versions of these dependent dlls.

For example here are the manifest dependency details for the common control and version 8.0 C runtime libraries:

<dependentAssembly>
    <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="X86"
        publicKeyToken="6595b64144ccf1df"
        language="*"
    />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity
        type="win32"
        name="Microsoft.VC80.CRT"
        version="8.0.50608.0"
        processorArchitecture="x86"
        publicKeyToken="1fc8b3b9a1e18e3b" />
</dependentAssembly>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top