zoukankan      html  css  js  c++  java
  • Windows XP Manifest in Delphi

    Find out how you can include the manifest into a Delphi project to allow your application to share the same look and feel of Windows XP.
       
    More of this Feature
     Download Demo Project
    Join the Discussion
    "Post your questions, concerns, views and comments to this article..." Discuss!
    Related Resources
     Working with resources Win/Shell/API programming Book: Delphi Developer's Guide to XML About XML and Delphi

    Article submitted by: Michael A. Allen

    Why? Windows XP has a theme manager that changes the look and feel for most all of the standard windows controls. Microsoft claims that older versions of the comctl32.dll contained support code to maintain different platforms of the Windows OS. The introduction of "themes" in Windows XP was the rationale behind cleaning up the code contained within the comctl32.dll. Now they are maintaining two versions of the same control. The older (version 5.8) version which is backward compatible to all flavors of Windows (XP included) and the newer (Version 6) version which is compatible with XP alone (and any future windows platforms).

    By default, all programs written under Windows XP will default to version 5.8, maintaining the same look and feel of the legacy windows applications. In order to enter 6.0 of the control, you must include in your application, a Manifest that the OS will read in order for the theme manager to take control of drawing the new look and feel for the Windows XP environment.

    What? What exactly is the manifest, and how does this play into making my application use version 6.0 of the comctl32.dll library? The manifest is an XML document that must be included into the resource section of your executable. Typically this resource section is reserved for things like images, icons and mouse cursors. Even string tables can be included in this resource section. The XML document, when placed in the right spot within the resource section will allow Windows XP to decide which version of the comctl32.dll to use when binding.

    How? To include this XML manifest into your application, you must first know the constants set forth by Microsoft. When entering a new resource into your executable, there is a group number and item number associated with the resource. The group number is typically labeled with a friendly name. For instance, if you use your resource explorer demo application that came shipped with Delphi (under {$delphi}Demos) you will notice groups named "Strings", "Bitmaps", "Icons" or "Cursors" - these names are actually just friendly representations of a group number. The group number for "Manifests" is 24, as per the C headers distributed by Microsoft. The manifest item number to determine the version of the comctl32.dll library is 1 (also per the C headers distributed by Microsoft). This information becomes necessary when building our new resource (.RES file) to be linked in with our executables.

    To create the .RES file that we need, we need to first create a .RC file that assigns our manifest XML document to the appropriate group number and line item number. In the ZIP file included with this document, you'll notice two files:

    1) WindowsXP.RC and 2) WindowsXP.Manifest

    The WindowsXP.RC contains our instructions to include the WindowsXP.Manifest (XML) document as line item 1 bound to group 24. The contents of the WindowsXP.RC looks like this:

    1 24 "WindowsXP.Manifest"

    The manifest itself, is an XML document that contains information about the application you are writing as well as information concerning the version of the comctl32.dll to use. It's contents will require a certain amount of customization to fit your application, but will look similar to this:

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

    Now that we have these two files in place, we need to use Delphi's resource compiler to compile the .RC file. Doing so will result in a WindowsXP.RES file that we can include in our applications. From the command line, type following (keep in mind, you should include the Delphi's BIN directory in our path for this to work)

    C:Project1> brcc32 WindowsXP.RC

    After you have compiled the WindowsXP.RC file, you see a WindowsXP.RES file in the same directory. The final step to making your application Windows XP compatible is to include this resource in your application. The easiest way to do this, is to include either in your project file (.DPR) or your primary form, the following compiler directive:

    {$R WindowsXP.RES}

    You should probably place this immediately after the {$R *.DFM} compiler directive that is already in your application, directly after the implementation clause.

    Once you have included your WindowsXP.RES file into your application, compile your application and run it. The Windows theme manager, to adapt the same look and feel of other applications written for Windows XP, now instantly converts your windows controls.

    Warnings Microsoft warns all developers that they have in fact eliminated a lot of the support code in the comctl32.dll library, and that you should always test thoroughly to ensure all aspects of your controls work properly before distribution. It has been my experience that there are in fact some compatibility issues with Delphi. So far, the only discrepancy I have found was in the TListView component. If you use the TListView component with the view style of vsReport, you run into a problem using the TColumns property. During runtime, you will generate a kernel error if you attempt to use column headers with said view style.

    If you need some more help on this subject, please post your comments to the Delphi Programming Forum.

    In any case, download the demo project - and try it for yourself.

    All graphics (if any) in this feature created by Zarko Gajic.

    More Delphi
    · Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time.  · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
    · NEXT ARTICLE: Perfect Gift: Delphi 6 and Kylix (almost) for FREE. For a limited time only, Borland Cross-Platform RAD is available to Visual Basic developers at the special price! Buy Delphi 6 professional at the half price and get Kylix Desktop and Delux Standard for FREE.
  • 相关阅读:
    【高级内部资料】.NET数据批量写入性能分析 第二篇
    负载均衡原理与实践详解 第五篇 负载均衡时数据包流程详解
    负载均衡原理与实践详解 第三篇 服务器负载均衡的基本概念网络基础
    如何提高Linq查询的性能(上)
    【全面解析DeepZoom 之二】Silverlight2及Deep Zoom环境的搭建
    关于让WPF软件界面支持全球化和本地化
    在WPF中自定义控件(3) CustomControl (上)
    【全面解析DeepZoom 之一】酷!Deep Zoom
    谈谈我理解的WPF团队模型——在UI Designer与Developer之间
    [WPF疑难]在WPF中显示动态GIF
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/3208122.html
Copyright © 2011-2022 走看看