Author Topic: Visual Styles  (Read 5560 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Visual Styles
« on: August 29, 2011, 06:35:41 PM »
 
Windows XP introduced visual styles, a way to provide a new look to the common controls, with ComCtl32.dll version 6.0. Unlike previous versions of this library, version 6.0 is not redistributable.

There are two ways to make an existing application theme aware:

  • Create a manifest file named <MyApp>.exe.manifest, where Myapp is the name of your application, in the same directory where your application resides.
  • Create a manifest file and add it to the resource file used by your application.

Additionaly, the application must initialize the common controls library by calling the InitCommonControls or InitCommonControlsEx API functions.

The manifest XML document required to use XP visual styles is as follows:

Code: [Select]
<?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.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="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>

To compile the manifest as a resource in your application, the manifest must appear as a resource type RT_MANIFEST(24) with the identifier CREATEPROCESS_MANIFEST_RESOURCE_ID(1):

Code: [Select]
#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
#define RT_MANIFEST 24
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyManifest.xml"
or you can use the actual numeric values:

Code: [Select]
1 24 "MyManifest.xml"

For a complete explanation of how to make and use resource files with PowerBASIC see the topic "Resource Files" in the help file or manual of your compiler.

Beginning with PowerBASIC 10, you can use the #RESOURCE directive to include the manifest directly:

Code: [Select]
#RESOURCE MANIFEST,  1, "MyManifest.xml"

MSDN documentation: http://msdn.microsoft.com/en-us/library/bb773187%28VS.85%29.aspx

Attached to this post there is a help file with the Visual Styles documentation adapted to the PowerBASIC syntax.
« Last Edit: August 31, 2011, 10:59:04 PM by José Roca »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Using Visual Styles with a Custom Control
« Reply #1 on: August 29, 2011, 06:36:22 PM »
 
Using Visual Styles with a Custom Control

To enable a control to apply visual styles:

  • 1. Call OpenThemeData and pass the hwnd (window handle) of the control you want to apply visual styles to and a class list that describes the control's type. If it succeeds, OpenThemeData returns a theme handle, otherwise it returns NULL (it can fail because the visual style manager is disabled or because the current visual style does not supply specific information for a given control). If the return value is NULL use nonvisual style drawing functions.

  • 2. To draw the control, call DrawThemeBackground and pass the following:

    • Theme handle returned from OpenThemeData and the HDC (Handle of Device Context) to use for rendering the control.
    • Part identifier that describes the part of the control to render. For information about control parts and states, see Parts and States
    • State identifier that describes the current state of the part.
    • Pointer to the RECT structure that contains the coordinates of the rectangle where the control will be rendered.

  • 3. Some parts can be partially transparent. You can determine this by calling IsThemeBackgroundPartiallyTransparent with the theme handle, a control part, and a control state.

  • 4. If your control draws text, position the text within the content rectangle of the control and select a font.

    • To determine the location of the content rectangle call GetThemeBackgroundContentRect.
    • Add your desired font to the device context (DC) then call DrawThemeText. This function enables visual effects such as shadowed text in some controls.

  • 5. When your control receives a WM_THEMECHANGED message, it should do the following:

    • Call CloseThemeData to close the existing theme handle.
    • Call OpenThemeData to get the theme handle for the newly loaded visual style.

              ' This code sample illustrates the two calls.
              CASE %WM_THEMECHANGED
                   CloseThemeData (hTheme)
                   hTheme = OpenThemeData (hwnd, UCODE$("<ClassName>"))

  • 6. When your control receives a WM_DESTROY message, call CloseThemeData to release the theme handle that was returned when you called OpenThemeData.

Note  You can find the headers to use XP Visual Styles with PowerBASIC in Uxtheme.inc, part of my Windows API headers.

See also Button_SetImageList for another way of using images in buttons if you are going to use them only in Windows XP or higher.