How do I make my application use the Windows theme?

后端 未结 5 1517
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 15:56

I\'m working with some windows API to create a little application. I already created the buttons, windows, alright.

But the problem is the components I created don\'t lo

相关标签:
5条回答
  • 2021-02-06 16:26

    For an application using windows controls, that is documented in this msdn article

    Edit: To make a long story short, Windows needs to know for an application if it was intended to use the new style controls. Some older apps just aren't compatible with the new skinned looks of XP and later. Each exe should therefore declare with which version it is compatible in a manifest, an embedded xml file in the executable. The manifest is used for other things like declaring what you are or aren't compatible with (DLL versions, 120 dpi) as well as registration-free com.

    0 讨论(0)
  • 2021-02-06 16:28

    In Visual Styles Reference: Functions of MSDN, I found an interesting functions, that is, SetWindowTheme(). It can be used to either to apply or remove visual style to/from a control/window, there are several steps need to be done to enable Visual Style in an application.

    To use Windows Theme api, you'll need JwaUxTheme unit of JEDI API Library.

    However, applying theme from Windows Theme files (.theme) to an application seems has to be done by turning off visual style from controls and write owner drawn controls based on information from .theme files. MSDN has a documentation about .theme file specification (see the first reference below).

    Some good references:

    • Creating and Installing Theme Files
    • Fully themed Windows Vista Controls
    • Creating Windows Vista Ready Applications with Delphi

    Is Windows Presentation Foundation (WPF) Themes bad? There is a code example how to load it here.

    If you use VCL, Theme Engine and Skin Engine has a complete support of themes for Windows XP.

    If beauty application is your priority (without supports for Windows themes), I think, BusinessSkinForm and DynamicSkinForm is the best choice.

    0 讨论(0)
  • 2021-02-06 16:47

    If you're using Delphi 2007 or later, Project > Options > Application > Use Windows Themes needs to be checked.

    (This should be automatically checked for new applications).

    0 讨论(0)
  • 2021-02-06 16:48

    If your executable name is YourAppName.exe then, create a manifest file named YourAppName.exe.manifest in the same directory where the executable application is.

    YourAppName.exe.manifest:

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

    For embedding manifest file into executable use mt.exe commandline syntax:

    mt.exe –manifest YourAppName.exe.manifest -outputresource:YourAppName.exe;1

    0 讨论(0)
  • 2021-02-06 16:50
    1. It depends on what version of Delphi you're using. IIRC pre-Delphi 6 you need to add the needed manifest by hand. D7 and later has a component that need to be dropped on a form to add theme support (it simply adds the manifest), until D2007 IIRC added a simple check in the project options.
    2. Earlier version of Delphi won't show themed design form. You will see themes only at run time.
    3. Not all controls may support themes. Themes require the proper draw API to be called, if a control doesn't comply it won't be themed. The standard grid is a good example, it isn't draw themed until a late version.
    0 讨论(0)
提交回复
热议问题