Appearance style of Windows XP

Source: Internet
Author: User

This article is only a preliminary document and will not be notified of any changes.

Summary:This document describes how to use Microsoft Windows XP to complete common tasks that are required to apply a visual style to an application.

Directory
  • Introduction
  • Comctl32.dll version 6
  • Visual style task
  • Use comctl32.dll 6 in applications that do not use third-party extensions
  • Use comctl32 6 in applications that use extensions, plug-ins, or in-process DLL
  • Use comctl32 6 in the control panel or in the DLL running through rundll32.exe
  • Apply the style to custom controls
  • Allows self-drawn controls to use the appearance style
  • Make the widget do not show the style in a pop-up dialog box or window
  • Use the uxtheme hypervisor to display widgets that do not have a look Style
  • Apply the style to HTML content
  • Causes the uxtheme hypervisor to ignore the top-level window
  • Use the 32-bit anti-distortion icon
  • Allows your applications to run properly in earlier versions of Windows XP and Windows.
  • Summary
Introduction

By using Microsoft Windows XP, you can now define the visual styles of controls and windows, such as simple colors, textures, and shapes. You can control each definition widget in the control or each widget in the non-client (frame and title) area of the window. Then, you can use the "appearance" tab in the Windows Control Panel to switch between the traditional and other available styles.

Windows XP provides a visual style. By using the Helper library and application programming interfaces (APIS), you can use the appearance style of Windows XP in your applications without changing too much code. For more information, see the Platform SDK documentation in the msdn library.

Comctl32.dll version 6

All applications running on Windows XP have a non-client area, including the window frame and non-client scroll bars. By default, the appearance style is applied to non-client regions. This means that the appearance of the non-client region is specified by the current installation style. To apply the appearance style to common controls in the client area, you must use comctl32.dll version 6 or later. Unlike earlier versions of comctl32.dll, comctl32.dll 6 cannot be reselected. The only way to use version 6 of the dynamic link library (DLL) is to use the operating system that contains it. Windows XP provides both version 5 and version 6. Comctl32.dll 6 contains user controls and common controls. By default, various applications use User Controls defined in user32.dll and common controls defined in comctl32.dll version 5.

If you want your application to use the appearance style, you must add an application declaration stating that if comctl32.dll version 6 is available, you should use it. Version 6 includes new options for some new controls and other controls, but the biggest change is the support for changing the appearance of the controls in the window.

Visual style task

To add a style to your control, you may need to perform the following tasks.

Use comctl32.dll 6 in applications that do not use third-party extensions

Below are some examples of applications that do not use third-party extensions.

  • Calculator

     

  • Freecell

     

  • Mine Clearance

     

  • Notepad

     

  • Card

To create a declaration and enable your application to use the appearance style, perform the following steps:

  1. Link to comctl32.lib and callInitcommoncontrols(See the Platform SDK documentation in the msdn library ).

     

  2. Add the file yourapp.exe. manifest to the source code tree in the following XML format:

    <? 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> here is your application description. </Description>

    <Dependency>

    <Dependentassembly>

    <Assemblyidentity

    Type = "Win32"

    Name = "Microsoft. Windows. Common-Controls"

    Version = "6.0.0.0"

    Processorarchitecture = "x86"

    Publickeytoken = "6595b64144ccf1df"

    Language = "*"

    />

    </Dependentassembly>

    </Dependency>

    </Assembly>

  3. Add the declaration to the application's resource file as follows:

    Createprocess_manifest_resource_id rt_manifest "yourapp.exe. manifest"

Note:If you add the previous item to a resource, you must set its format in one row. Alternatively, you can place the XML declaration file in the same directory as the executable file of the application. The operating system first loads the declaration from the file system, and then checks the resource part of the executable file. The file system version is preferred.

Use comctl32 6 in applications that use extensions, plug-ins, or in-process DLL

The following are examples of applications that use extensions.

  • Microsoft Management Console (mmc.exe)

     

  • Windows Shell

     

  • Microsoft Visual Studio

To create a declaration and enable your application to use the appearance style, perform the following steps:

  1. Use the Windows XP beta 2 SDK or a later version.

     

  2. Includes the title file of common controls, as shown below:

    # Include "commctrl. H"

  3. Define the compiler variable Preprocessing Program definition as follows:

    # Define sidebyside_commoncontrols 1

    Add the file yourapp. manifest to the source code tree in the following XML format:

    <? 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> here is your application description. </Description>

    <Dependency>

    <Dependentassembly>

    <Assemblyidentity

    Type = "Win32"

    Name = "Microsoft. Windows. Common-Controls"

    Version = "6.0.0.0"

    Processorarchitecture = "x86"

    Publickeytoken = "6595b64144ccf1df"

    Language = "*"

    />

    </Dependentassembly>

    </Dependency>

    </Assembly>

  4. Add the declaration to the application's resource file as follows:

    Createprocess_manifest_resource_id rt_manifest "yourapp. manifest"

    Winuser. RH includes the following definitions:

    # Define createprocess_manifest_resource_id 1

    # Define control_panel_resource_id 123

    # Define rt_manifest 24

Use comctl32 6 in the control panel or in the DLL running through rundll32.exe

To create a declaration and enable your application to use the appearance style, perform the following steps:

  1. Link to comctl32.lib and callInitcommoncontrols.

     

  2. Add the file yourapp. Cpl. manifest to the source code tree in the following XML format:

    <? 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> here is your application description. </Description>

    <Dependency>

    <Dependentassembly>

    <Assemblyidentity

    Type = "Win32"

    Name = "Microsoft. Windows. Common-Controls"

    Version = "6.0.0.0"

    Processorarchitecture = "x86"

    Publickeytoken = "6595b64144ccf1df"

    Language = "*"

    />

    </Dependentassembly>

    </Dependency>

    </Assembly>

  3. Add the declaration to the application's resource file as follows:

    Control_panel_resource_id rt_manifest "yourcpl. manifest"

Note:After writing the control panel application, place it in the corresponding category. The control panel now supports the classification of Control Panel applications. That is to say, you can assign an identifier to the control panel application and divide it into several task areas, for example, add or delete programs, appearance and topic, date, time, language, and Region options ".

Apply the style to custom controls

The title file uxtheme. h defines the uxtheme API referenced in the steps for adding a style to the control and in the corresponding code example. Each element of the API is described in the Platform SDK. This section describes how to apply a style to a widget and provides a drawing code example and tips for plotting controls.

To enable the control to apply the appearance style, perform the following steps:

  1. CallOpenthemedataThe hwnd of the visual control will be applied to the list of classes that describe the control type. Each class is defined in tmschema. h.OpenthemedataReturns an htheme handle. However, if the style manager is disabled or the current style does not provide specific information for the given control, this function returns NULL. If the return value is null, a non-visual drawing function is used.

     

  2. To draw controls, callDrawthemebackgroundAnd pass the following content:
    • OpenthemedataThe returned theme handle HDC, which is used to render the control.

       

    • The identifier of the widget to be rendered. For more information about the widget's parts and status, see topic parts and status ".

       

    • Status identifier, used to indicate the current status of the part.

       

    • Pointer to the rect structure, which contains the coordinates of the rectangle that will render the control.
  3. Some parts can be translucent. To determine the transparency of a widget, you can call the widget using the theme handle, widget, and Widget status.Isthemebackgroundpartiallytransparent.

     

  4. If the control draws text, place the text in the control's content rectangle and select a font.
    • To determine the position of the content rectangle, callGetthemebackgroundcontentrect.

       

    • Add the required font to the device context (DC), and then callDrawthemetext. This function enables the appearance effect, such as shadow text in some controls.
  5. After receiving the wm_themechanged message, the control should perform the following operations:
    • CallClosethemedataTo close the existing topic handle.

       

    • CallOpenthemedataTo obtain the theme handle of the newly loaded style.

       

    • The sample code shows the two calls.
      case WM_THEMECHANGED:    CloseThemeData (hTheme);    hTheme = OpenThemeData (hwnd, L"MyClassName");    
  6. After the control receives the wm_destroy message, it callsClosethemedataTo releaseOpenthemedata.
Drawing code example

The following code example shows how to draw a button control.

Htheme = NULL; htheme = openthemedata (hwndbutton, "button ");... Drawmycontrol (HDC, hwndbutton, htheme, istate );... If (htheme) {closetheme (htheme);} void drawmycontrol (HDC, hwnd hwndbutton, htheme, int istate) {rect RC, rccontent; tchar szbuttontext [255]; hresult hr; getwindowrect (hwndbutton, & rc); getwindowtext (hwndbutton, szbuttontext, arraysize (szbuttontext); If (htheme) {hR = trim (htheme, HDC, bp_button, istate, & rc, 0); // check the generated code. HR = require (htheme, bp_button, istate, & rc, & rccontent); HR = drawthemetext (htheme, HDC, bp_button, istate, szbuttontext, lstrlen (szbuttontext ), dt_center | dt_vcenter | dt_singleline, 0, & rccontent);} The appearance style is not used when the else {// draws the control. }}
Allows self-drawn controls to use the appearance style

In Windows XP, controls no longer only consist of lines and fill colors. Now they include rich textures and patterns that can change with the control status. This means that you cannot use existing programming elements to describe self-drawn controls that have the same appearance as those that have been applied. If your code contains a self-drawn control, you can select the following.

  • You can callSetwindowthemeTo close the topic of the control.
    SetWindowTheme (hwndButton, TEXT (" "), TEXT (" "));

    The control is displayed in the same way as in earlier versions of Windows.

  • You can continue to use the self-Drawing Method in the control, but some attributes will be ignored. For example, if you change the background color of a button, the button will be drawn as a button with an applied exterior style, but the background color is not the specified color. However, if you change the font, the button is drawn using the specified font.
Make the widget do not show the style in a pop-up dialog box or window

In some cases, an application has a custom draw control that does not apply the appearance style (even if other controls in the window have applied the appearance style ). You must callSetwindowtheme, You must also pass in the window handle of the control andPszsubappnameAndPszsubidlistInput an empty string. By callingSetwindowthemeFunction. The following code snippet shows how to create a button control and then callSetwindowthemeFunction to delete the appearance style of the button.

Hwnd hwndbutton; hwndbutton = createwindow (text ("button "),...); If (hwndbutton) {setwindowtheme (hwndbutton, text (""), text (""));}

Note:You can callSetwindowthemeBut pass null to two string parameters.

Use the uxtheme hypervisor to display widgets that do not have a look Style

If your control is not a common control, but you want it to have an appropriate appearance on a computer with a visual file installed, you can use one of the following methods.

  • The basic method is to use the system standard color. Most System Standard colors are set when the appearance style file is applied.

     

  • You can use components of other controls and present each component separately. For example, for a calendar control consisting of a grid, you can use each square formed by the grid as a toolbar button. Perform the following steps to program the square as a toolbar button.

    CallOpenthemedata, As shown below:

    OpenThemeData (hwnd, "Toolbar");

    Use the returned topic handle to present each square on the calendar.

  • To combine and match widgets, you can call a specified widget multiple times.OpenthemedataUse the corresponding theme handle to draw different parts. However, in some exterior styles, some parts may be incompatible with other parts.

     

  • Some dedicated applications must match the appearance of Windows XP At the control level or above, so they may need to detect the current loaded appearance style and design custom rendering that matches the appearance. This is useful for applications that provide a visual style architecture.
Apply the style to HTML content

Many applications are written in HTML and deployed as HTML applications (HTA) or Win32 applications. These applications use HTML or host webobject in their UI elements. When running on Windows XP, these applications will have the same appearance as Win32-based applications running on the same operating system. When applying a style to HTML content, consider the following:

  • The style related to HTML content is only applicable to inherent HTML controls, such as buttons, scroll bars, and selection controls. The appearance style of Windows XP is automatically applied to controls on HTML pages. If you do not want to apply the style to the page, use the meta tag with the attribute set to No. This meta tag is described in the following section.

     

  • Does not apply the style of the HTML page that has a stacked style sheet (CSS) (such as a background or border) modified. They will display the specified CSS attributes.

     

  • When most CSS attributes are specified as part of the content, they can be applied to elements with applied exterior styles.

     

  • You must add the Canadian dollar tag in the <META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
  • Note that the style may change the layout of the content. In addition, when you set certain attributes of the inherent HTML control (such as the width of the button), you may find that tags on the button cannot be read in some styles.

     

  • You must thoroughly test your content using the appearance style to determine whether the appearance style application has a negative impact on the content and layout. Make the necessary changes so that your content is displayed successfully.
Causes the uxtheme hypervisor to ignore the top-level window

To avoid applying a new style to a top-level window, consider the following:

  • If a window has an area applied, uxtheme manager assumes that the area is a dedicated window, and the window does not use the appearance style throughout its lifetime. Even if the parent window does not use the exterior style, the Child Window associated with the top-level window of the non-exterior style may still apply the exterior style.

     

  • If you apply an area to a top-level window and then delete it, the appearance style will not be automatically applied to the window. To apply the appearance style to the window, you must create a new window.

     

  • CallSetthemeapppropertiesBut does not pass the stap_allow_nonclient flag.

     

  • If the application is not calledSetthemeapppropertiesThe flag value is stap_allow_nonclient | stap_allow_controls | stap_allow_webcontent. It is assumed that the value will make the appearance of non-client areas, controls, and web content applications.
Use the 32-bit anti-distortion icon

Windows XP image list is an image set for some controls (such as List View Controls). It supports 32-bit anti-distortion icons and bitmaps. The color value uses 24 bits, while the 8 bits are used as the alpha channel on the icon. To create a list of images that can process 32-bit/bpp images, call the imagelist_create function and pass the ilc_color32 flag.

The icon format has not been changed, but the method for creating these icons has changed.

Icon format

To create a 32-bit icon correctly, follow these steps:

  • Create multiple images for each icon. These images are displayed.

Multiple images of the same icon
  • In medium, the first three images are in the 16-color mode, which is used in the safe mode.

     

  • The following three icons are used in Windows XP 256 color mode.

     

  • The last three icons have alpha channels and can only be used for Windows XP or later operating systems that run in 24-bit or higher color.

     

  • In the icon format, the order of these images is important. If the order is incorrect, Windows earlier versions may encounter errors when extracting these icons. Incorrectly extracting Icons can cause memory crashes and abnormal rendering.

     

  • In earlier versions of Windows, there were 10 icon resource restrictions, while Windows XP supported thousands of ICON resources.

Note:You can use third-party tools to generate Icon files and bitmaps containing alpha channels.

Allows your applications to run properly in earlier versions of Windows XP and Windows.

Most of the Windows XP exterior style architecture is used to make your product run normally on an old version of Windows that does not support changing the exterior of the control. To enable applications to run properly on multiple operating systems, note the following:

  • The declaration of installing an application in an earlier operating system does not affect the display of the control.

     

  • You must test your application to ensure that the current version does not depend on the features of comctl32.dll version 6.

     

  • Do not directly link to uxtheme. Lib. If you use the uxtheme API to add a style to a custom control, load the library as needed.

     

  • If the appearance style cannot achieve the expected results, write the error handling code for the instance.

     

  • If you are using features in comctl32.dll version 6 (such as tiled views or linked controls), you must handle situations where these controls cannot be used on your computer. Comctl32.dll version 6 cannot be reselected.
Summary

This document describes the tasks that must be executed when you apply a visual style to an application. It does not include all the tasks to be executed, but discusses some of the most common tasks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.