tags:

views:

409

answers:

4

I'm trying to make a button but it always looks like windows 95 flat button. How do I make it look vista style?

 hWndEdit = CreateWindowA("button", "Test",
  WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
100, 20, 140, 20, hWnd, NULL, NULL, NULL);

Where ami I going wrong? Thanks

+5  A: 

It can only look Vista style in Vista, mind you. Your application must also embed a manifest as per http://msdn.microsoft.com/en-us/library/ms997646.aspx to enable visual styles.

Nick Bedford
+2  A: 

You need to add a manifest for your .exe that specifies that you want to use themes. The default behavior is to use Win9x/NT/2K controls for the sake of compatibility - themed XP+ controls are slightly larger. This explains how to add such a manifest in detail.

Pavel Minaev
+3  A: 

Create a file named "MyApp.exe.manifest" in your project directory (MyApp is your application's name). Then open it with your fav editor and copy & past following code in it:

<?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="X86"    
    name="CompanyName.ProductName.YourApp"    
    type="win32"    
/>

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

And after you've done that, add this file to your Visual Studio project (right-click on the project icon and select "Add"->"Existing item".

Adding this manifest file to your VS solution is enough to have XP themes enabled.

Hope this helps...

StackedCrooked
+1  A: 

What is your build environment? If its Visual Studio 2005 or 2008, then all the other manifest advice does not apply as VS8 and up are already including manifest information.

In which case the easiest way to add a manifest dependency is to make use of a simple (microsoft specific) compiler directive that you add to some cpp or header file:

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

Including the manifest this way avoids messing up the c-runtime manifest dependencies or messing up the settings needed for UAC to work correctly.

Chris Becke