Search code examples
c++visual-c++windows-7win32gui

Windows 7 Button Styles in VC++


I am new to Visual C++ (I have programmed in the past in C not C++). I started creating some basic applications, with windows and controls and other things like those. When ran one of my apps dialog, see how it looks (don't look at the text in it, it just some text):

enter image description here

My problem is that any component I make, it looks like Windows 2000's ones. How can I get the Windows 7 Styles?

BTW. As I am new, I would be grateful if somebody will give me tips about good resources to learn from. :)


Solution

  • the compiler doesn't matter much but you need

    • an application manifest that specifies use of version 6 (or better) of the common controls

    • if you want to support Windows XP, a call to InitCommonControls (if I recall the name correctly, check it)

    The minimum complete manifest you need is

    <?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="*"
        name="CompanyName.ProductName.YourApplication"
        type="win32"
    />
    <description>Your application description here.</description>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>
    

    Store that as an UTF-8 file if you include national characters.

    For Visual Studio you only need the part about the common controls,

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
        </dependentAssembly>
    </dependency>
    </assembly>
    

    And specify this as an additional manifest in the project settings.


    A good resource to start Windows API level programming is my Windows API tutorial blog.

    The best book for that, which you will eventually need, is Petzold’s “Programming Windows”. In one of the editions before the (book's) transition to C#/.NET.