Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How do I change the folder icons in a DirectoryListBox?


This question is answered.


Permlink Replies: 6 - Last Post: Aug 2, 2017 3:52 PM Last Post By: Remy Lebeau (Te...
Carl Olsen

Posts: 124
Registered: 3/29/00
How do I change the folder icons in a DirectoryListBox?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 10:28 AM
Is there a way to change the icons used in a TDirectoryListBox? The existing folder icons are super-dated looking.

I'm using Delphi Berlin, if that matters.

I found one article here: http://edn.embarcadero.com/article/27508 but that seems a bit convoluted and likely way out of date.

Thanks!

Carl.

Edited by: Carl Olsen on Aug 2, 2017 10:28 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How do I change the folder icons in a DirectoryListBox? [Edit]
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 11:13 AM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

Is there a way to change the icons used in a TDirectoryListBox?

The icons are stored in your compiled executable's resources. You
would have to modify your executable with a resource editor after
compiling is done.

The existing folder icons are super-dated looking.

That is because it was designed way back in the Windows 3.1 days (and
why the component exists in the "Win 3.1" section of the component
palette).

You really should be using either:

1. the 2nd overloaded version of the RTL's SelectDirectory() function.

2. the Win32 API SHBrowseForFolder() function (which #1 wraps).

3. the VCL's TFileOpenDialog component with the fdoPickFolders option
enabled (Vista+ only)

4. the Win32 IFileDialog interface (Vista+ only), with the
FOS_PICKFOLDERS flag enabled (which #3 wraps).

5. a 3rd party ListBox/ListView component that mimics what Windows
Explorer displays.

I found one article here: http://edn.embarcadero.com/article/27508
but that seems a bit convoluted and likely way out of date.

That article has nothing to do with this issue. It describes how to
customize folder icons that are displaying in Windows Explorer (and
dialogs that embed Explorer), which is not what you are using here.
TDirectoryListBox is a completely custom dialog written in VCL, and has
nothing to do with what that article is talking about.

--
Remy Lebeau (TeamB)
Carl Olsen

Posts: 124
Registered: 3/29/00
Re: How do I change the folder icons in a DirectoryListBox? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 11:28 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks Remy,

As usual you are a fountain of knowledge, and I super appreciate your help!

Regarding this comment:

Remy Lebeau (TeamB) wrote:
The icons are stored in your compiled executable's resources. You
would have to modify your executable with a resource editor after
compiling is done.

Is it possible to re-load the resources at runtime? For example, have a folder of glyphs, and then somehow override whatever is in memory with one loaded from a file? I'm pretty sure the answer is "no", but I figure I would ask.

Otherwise, I see tools for modifying the .exe after the fact like you suggest. If you have a recommendation for such a tool, I would love to hear it. Otherwise, I know that Google is my friend here.

Thanks!

Carl.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How do I change the folder icons in a DirectoryListBox? [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 12:16 PM   in response to: Carl Olsen in response to: Carl Olsen
El 02/08/2017 a las 20:28, Carl Olsen escribió:
Thanks Remy,

As usual you are a fountain of knowledge, and I super appreciate your help!

Regarding this comment:

Remy Lebeau (TeamB) wrote:
The icons are stored in your compiled executable's resources. You
would have to modify your executable with a resource editor after
compiling is done.

Is it possible to re-load the resources at runtime? For example, have a folder of glyphs, and then somehow override whatever is in memory with one loaded from a file? I'm pretty sure the answer is "no", but I figure I would ask.

Otherwise, I see tools for modifying the .exe after the fact like you suggest. If you have a recommendation for such a tool, I would love to hear it. Otherwise, I know that Google is my friend here.

You can modify the FileCtrl.res file with a resource editor.

There are 2 copies of that file:
One for the Win32 platform: $(BDS)\Lib\win32\release
One for the Win64 platform: $(BDS)\Lib\win64\release

Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: How do I change the folder icons in a DirectoryListBox? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 1:16 PM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

Otherwise, I see tools for modifying the .exe after the fact like you
suggest. If you have a recommendation for such a tool, I would love
to hear it.

https://stackoverflow.com/a/7000218/95954


--
Rudy Velthuis http://www.rvelthuis.de

"He uses statistics as a drunken man uses lamp-posts...
for support rather than illumination."
-- Andrew Lang (1844-1912)

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How do I change the folder icons in a DirectoryListBox? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 3:52 PM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

Is it possible to re-load the resources at runtime?

Not directly, no. The EXE is locked while it is running, it cannot
modify its own resources.

However, there are simplier solutions.

TDirectoryListBox loads its images at runtime into internal TBitmap
objects named ClosedBMP, OpenedBMP, and CurrentBMP, and those objects
are fortunately declared as 'protected', so there are ways to access
them directly so you can load them with different images at runtime.

You could write an accessor class:

type
  TDirectoryListBoxAccess = class(TDirectoryListBox)
  end;
 
procedure TMyForm.FormCreate(Sender: TObject);
begin
  TDirectoryListBoxAccess(DirectoryListBox1).ClosedBMP.LoadFrom...();
  TDirectoryListBoxAccess(DirectoryListBox1).OpenedBMP.LoadFrom...();
  TDirectoryListBoxAccess(DirectoryListBox1).CurrentBMP.LoadFrom...();
end;


You could derive a new component from TDirectoryListBox and use that in
your project instead of the standard component. Override its virtual
ReadBitmaps() method, which is called to populate those same TBitmap
images:

type
  TMyDirectoryListBox = class(TDirectoryListBox)
  protected
    procedure ReadBitmaps; override;
  end;
 
procedure TMyDirectoryListBox.ReadBitmaps;
begin
  ClosedBMP.LoadFrom...();
  OpenedBMP.LoadFrom...();
  CurrentBMP.LoadFrom...();
end;


If you don't want to install such a component into the IDE, a simplier
way to use it would be to write is as an interposer class directly in
the same unit that uses it, just declare it above the Form declaration:

type
  TDirectoryListBox = class(FileCtrl.TDirectoryListBox)
  protected
    procedure ReadBitmaps; override;
  end;
 
  TMyForm = class(TForm)
    DirectoryListBox1: TDirectoryListBox;
    ...
  end;
 
procedure TDirectoryListBox.ReadBitmaps;
begin
  ClosedBMP.LoadFrom...();
  OpenedBMP.LoadFrom...();
  CurrentBMP.LoadFrom...();
end;


Otherwise, I see tools for modifying the .exe after the fact like you
suggest. If you have a recommendation for such a tool, I would love
to hear it.

There are plenty of 3rd party resource editors readily available and
easy to find. XN Resource Editor is a popular choice for Delphi apps
(because it has built-in support for reading DFMs), but any resource
editor will work. You would need to modify the 'OPENFOLDER',
'CLOSEDFOLDER', and 'CURRENTFOLDER' images.

--
Remy Lebeau (TeamB)
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: How do I change the folder icons in a DirectoryListBox? [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2017 11:46 AM   in response to: Carl Olsen in response to: Carl Olsen
Carl Olsen wrote:

Is there a way to change the icons used in a TDirectoryListBox? The
existing folder icons are super-dated looking.

Since TDirectoryListBox is a Win3.1 component ported over to 32 bit
Delphi, that comes as no surprise.

If you have 10.2 Tokyo, you can use the TRzShellTreeView component
instead. It is installed by default, AFAIK.

In earlier versions, you might be able to install the
vcl.shell.shellctrls and other vcl.shell*.pas files (in the VCL source
directory), but some units like RootEdit.pas and ShellReg.pas seem to
be missing. and so are the packages vclshlctrls.dpk and
dclshlctrls.pdk. The latter is the design-time package needed to
install them. The former is the runtime package.

In versions **before** XE7, you might be able to find these packages
too. They come in the samples directory, not in the VCL source
directory.

I have no idea why they were discontinued in XE7 and later. Perhaps
they are/were available through GetIt? I can't check that right now.

--
Rudy Velthuis http://www.rvelthuis.de

"Go on, get out. Last words are for fools who haven't said
enough." -- Karl Marx, dying words to his housekeeper.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02