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
But if you enable the Vcl Styles, the images in the header are lost.
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
... ... 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; ... ...
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.
initialization TStyleManager.Engine.RegisterStyleHook(TListView, TListViewStyleHookFix);
April 26, 2013 at 1:03 am
Is it possible to use this code in lazarus?
April 26, 2013 at 1:47 am
No, the Vcl Styles are just part of Delphi.
January 25, 2015 at 10:29 pm
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.
January 25, 2015 at 10:35 pm
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.