Recent

Author Topic: ShellTreeView and system icons  (Read 18604 times)

Alexandr F

  • New Member
  • *
  • Posts: 26
ShellTreeView and system icons
« on: February 21, 2016, 06:14:51 pm »
I would like to use ShellTreeView with system icons (like in Windows Explorer). I use Windows.

I try next:
 
IconListHandle := SHGetFileInfo('', 0, FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
TreeView_SetImageList(ShellTreeView1.Handle, IconListHandle, TVSIL_NORMAL );

But icons are not displayed. In Delphi 7 this code work properly, icons are displayed.

I'm try to read back a handle of Imagelist form ShellTreeView:

IconListHandle := TreeView_GetImageList(ShellTreeView, TVSIL_NORMAL );

and IconListHandle always is zero (I think should be not zero).
« Last Edit: February 21, 2016, 06:56:27 pm by Alexandr F »

PeterX

  • Sr. Member
  • ****
  • Posts: 404
usually using latest Lazarus release version with Windows 10

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: ShellTreeView and system icons
« Reply #2 on: February 07, 2021, 02:26:56 pm »
Trying to port D7 apps to Lazarus (2.0.10, on and exclusively for Windows 64 bit), i get stuck with this issue TreeView_SetImageList for to retrieve System icons and to use them in TTreeView.
Yes, such similar does work for Listview and Get/Set_Imagelist. But not for Treeview/ShellTreeView.
-
Seeing all the workarounds along (here and formum DE) dealing with this issue, they are working with clones/copies of the system icons storing them in an own ImageList.  But that's not the preferred way i try to do it. I would like to assign the system image list to a treeview image list directly. Otherwise, performance decrease with many file sytem objects will occur.
Unfortunately, a direct handle assignment won't work too, so TreeView_SetImageList  would be my last resort.
-
My question is: is there any concrete sample that proves by evidence that TreeView_SetImageList  will work with the LCL treeview?
Or is it so that this will never work because the lcl treeview is constructed differently (following the cross platform paradigm)?
If the latter is true: what's the recommended strategy to follow?

Lazarus 3.2  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: ShellTreeView and system icons
« Reply #3 on: February 07, 2021, 03:50:03 pm »
It would be interesting to see if this worked before Laz 2.0. If it did it would be an indication that the issue was created by the redesign of the new multi-resolution image list for Laz 2.0+.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: ShellTreeView and system icons
« Reply #4 on: February 07, 2021, 04:22:20 pm »
Thanks for attention! No, i cannot answer this; i'm new with Lazarus as of current 2.0.10.
But reading heavily around in all forums available i found the question raised along the last ten years repeatedly, without never receiving a concrete concise positive reply. What i solely found are a couple of workarounds, dealing with copies of the system images with icons/bitmaps that need to be created and stored in a target imagelist that, then, is assigned to the treeview.images.
That's too much traffic when dealing with much objects. - So i would assume it did never work.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: ShellTreeView and system icons
« Reply #5 on: February 10, 2021, 02:38:23 pm »
Sorry for to ask again:
Did anybody work successfully with TreeView_SetImageList for to attach Windows system icons to a treeview?

Or does anybody know whether that won't work by principle (due to a special implementation of the widget)?
Does anybody know a good approach without series of physical copies?

Any hint would be appreciated very much!
Lazarus 3.2  FPC 3.2.2 Win10 64bit

Ally

  • Jr. Member
  • **
  • Posts: 52
Re: ShellTreeView and system icons
« Reply #6 on: February 10, 2021, 05:05:09 pm »
Hello d7_2_laz,

the post is a bit older, but maybe it will help you:

https://forum.lazarus.freepascal.org/index.php/topic,12300.0.html

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: ShellTreeView and system icons
« Reply #7 on: February 10, 2021, 05:54:15 pm »
Hello Ally,
thanks for having replied! Yes, i already noticed this article, but at the end it's about ListView_SetImageList (which is working fine .... - underlying Windows control) and not  about TreeView_SetImageList (which for me has no effect at all.   as maybe Lazarus Treeview for the Windows platform does not use an underlying Windows control - cross-platform perspective -  ., i would guess ) .
Although the artiicle's example is commented as "You can do same thing for TShellTreeView. ".  It seems not, and exactly this is the problem.

And yes, there are many examples one may find that spend system icons to the treeview, using icon and/or bitmap copy operations. Regarding speed that's not the way it should be expected to work.
In Delphi you can attach system image list to a treeview by hanle assignment. In Laz. not, as it does not expose those handle.
Alternatively in Delphi you can call TreeView_SetImageList  tor attachment, but after a lot of testing and readiing it appears to me that won't work.

So i did raise the quesetion, whether it is expected to work or not, and, if not, what should be the recommended strategy.
Lazarus 3.2  FPC 3.2.2 Win10 64bit

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: ShellTreeView and system icons
« Reply #8 on: February 10, 2021, 07:03:57 pm »
So i did raise the quesetion, whether it is expected to work or not, and, if not, what should be the recommended strategy.
In lazarus TListView is rendered entirely via a widget, but TTreeView images are rendered using LCL.
Use OwnerDraw, extracting icons from the system image list as needed.

balazsszekely

  • Guest
Re: ShellTreeView and system icons
« Reply #9 on: February 10, 2021, 08:45:03 pm »
@d7_2_laz

See attached project.
« Last Edit: February 10, 2021, 09:18:08 pm by GetMem »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: ShellTreeView and system icons
« Reply #10 on: February 10, 2021, 11:18:38 pm »
GetMem, can I ask you to complete the example with code for the TShellListView. It's an excellent sample for reference.

balazsszekely

  • Guest
Re: ShellTreeView and system icons
« Reply #11 on: February 11, 2021, 08:37:12 am »
GetMem, can I ask you to complete the example with code for the TShellListView. It's an excellent sample for reference.

Attached a full example(TShellTreeView, TShellListView included).

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: ShellTreeView and system icons
« Reply #12 on: February 11, 2021, 12:19:22 pm »
Thanks a lot. Very helpful. Where to put it? wiki? CCR/applications? Lazarus/examples/?

Looking through the code I found two things for improvement (see my attachment):
- Fixed scaling of the image sizes (tested on Win 96ppi and 144ppi).
- No more explicit conversion UTF16ToUTF8 needed since FPC3+ where it is handled automatically.

El Salvador

  • Full Member
  • ***
  • Posts: 134
Re: ShellTreeView and system icons
« Reply #13 on: February 11, 2021, 12:40:09 pm »
And in Linux, is it more difficult to do same thing?

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: ShellTreeView and system icons
« Reply #14 on: February 11, 2021, 12:44:50 pm »
Kind thanks to all of you that have replied!
GetMem, this is the best demo i could find around! I would fully support wp that it should have the best place as a reference for all that are fighting with this problem. At least for the Windows part - in the Windows world shell explorer controls without system icons are absolutely not thinkable!

However i have two remarks - please apologize a laz. newbie.
The first thing is that we need interims copies of the icons again - AddIcon, so using not iIcon (index only) but hIcon (access to the icon object) in this operation.
The icons are copied and afterwards they will be accessed again for the drawing.
You will see noticeable speed difference when eg. (this is my standard check) opening windows\system32 with thousand objects; compare the opening time against the ms explorer. Or compare against any Delphi app that was able to to direct icon list attachments by handle assignment, or via TreeVew_SetImageList.
Yes - in most of the normal uses cases it is finely fast and fast enough. Thinking in the perspective of a file explorer there is room for speed improvement.

For those reason, for the Listview i would prefer to use ListView_SetImageList.
The link mentioned by Ally (above) gives a good starting point. As well as that one:
https://forum.lazarus.freepascal.org/index.php/topic,35669.msg236441.html#msg236441
Here, see routine TShellListView1FileAdded  (although it is not needed and i would not do a call of SHGetFileInfoW for each file added; better do it only once for a folder).

The second thing is: avoid duplication of the copies. The AddIcon will (at least this is my understanding) do 6000 AddIcons of the object and Draws afterwards, and if the folder / node is entered again later, those 6000 objects will be added 6000 times again, Am i right?
At a third visit of the folder, again 6000 adds?  Please correct me if i'm in error, i would be glad.
For this reason some of the workarounds i did mention erlier try to accomplish that with a kind of duplicate check; attempts that are working more or less sufficiently.

For those two reasons i was happy about the suggestion of ASerge (use ownerdraw). I was suprised and think it makes a good sense. We could access the icon objects directly, and access them via without unwanted intermediate copy operations, and they will not inflate an Imagelist.
Personally for me and in my special context i'll try if i could achieve results here.

ASerge, did you mean TListView  is entirely built by LCL?  if it is able to allow Listview_SetImagelist, the more it would be desirable that the treeview allows such similar.

Please correct me if my thinking is wrong. And many thanks again a lot for all of your contributions!

Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018