Skip to content
The Road to Delphi — Delphi, VCL, VCL Styles, UxTheme and WinAPI

Added new vcl style hook to the Vcl Styles Utils to fix QC #108678, #108875 (XE2 and XE3)

, , ,

I just added a new vcl style hook (TListViewStyleHookFix) for the TListView component in the Vcl Styles Utils project to fix the QC #108678, #108875 (XE2 and XE3)

The issue reported in both reports, is that the images are not displayed in the TListView header with the VCL Styles enabled.

When you uses the Windows Theme in a TListView with images in the header will look like so

LVWindows

But if you enable the Vcl Styles, the images in the header are lost.

LVStyles2

The issue is located in the TListViewStyleHook.DrawHeaderSection method, this method must paint the image and text of each section of the header of the ListView.

This is part of the code with the bug
[sourcecode language=”delphi” wraplines=”false”]
…
…
ImageList := SendMessage(Handle, HDM_GETIMAGELIST, 0, 0);
Item.Mask := HDI_FORMAT or HDI_IMAGE;
InflateRect(R, -2, -2);
if (ImageList <> 0) and Header_GetItem(Handle, Index, Item) then
begin
if Item.fmt and HDF_IMAGE = HDF_IMAGE then
ImageList_Draw(ImageList, Item.iImage, Canvas.Handle, R.Left, R.Top, ILD_TRANSPARENT);
ImageList_GetIconSize(ImageList, IconWidth, IconHeight);
Inc(R.Left, IconWidth + 5);
end;
…
…
[/sourcecode]

The problem with the above code is that the SendMessage function with the HDM_GETIMAGELIST message (which is used to get the current imagelist) is not using the proper Handle. The above code is passing the handle of the ListView, but must pass the handle of the Header control, the same applies to the call to the Header_GetItem method.

The TListViewStyleHookFix introduces a new DrawHeaderSection method which passes the handle of the header control and fix the issue. You can use this Stylehook adding Vcl.Styles.Fixes unit to you uses clause and then register the hook on this way.

[sourcecode language=”delphi” wraplines=”false”]
initialization
TStyleManager.Engine.RegisterStyleHook(TListView, TListViewStyleHookFix);
[/sourcecode]

LVStylesFix

4 responses

  1. Is it possible to use this code in lazarus?

    1. No, the Vcl Styles are just part of Delphi.

      1. I followed the instructions, using Delphi XE6, but I get Undeclared Identifier: TListViewStyleHookFix. I have added Vcl.ExtCtrls, Vcl.Styles.Fixes to my uses clause in the main form.

        1. Hi Daniel, this fix is only for XE2 and XE3. The Vcl.Styles.Fixes unit uses conditional compilation to add the TListViewStyleHookFix class, so how you are using XE6 this class is not added to the code.

Leave a Reply