Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

Explorer

An example of how Windows Explorer works as a file manager and can be integrated into any project.

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Explorer:

Compiler 10 Seattle 10 1 Berlin 10 2 Tokyo 10 3 Rio
10 4 Sydney 11 Alexandria 12 Athens
Components None

File Explorer, previously known as Windows Explorer, is a file manager application and default desktop environment that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface for accessing the file systems, as well as user interface elements such as the taskbar and desktop.

The application was renamed from "Windows Explorer" to "File Explorer" in Windows 8; however, the old name of "Windows Explorer" can still be seen in the Windows Task Manager.

v1.0.1

  • BugFix Menu Show Details range checking
  • BugFix StatusBar Panel [2] missed

v1.0.2

  • Add Added more features
  • Locate Computer onTop Item
  • Create File Formats (Excel, Word, Rar, Zip)
  • Folder navigation backwards
  • Search File Mode in Folder

File Explorer is the default user interface for accessing and managing the file systems, but it is possible to perform such tasks on Windows without File Explorer. For example, the File ▸ Run menu option in Task Manager on Windows NT or later functions independently of File Explorer, as do commands run within a command prompt window.

After a user logs in, the explorer process is created by the userinit process. Userinit performs some initialization of the user environment (such as running the login script and applying group policies) and then looks in the registry at the Shell value and creates a process to run the system-defined shell – by default, Explorer.exe. Then Userinit exits. This is why Explorer.exe is shown by various process explorers with no parent – its parent has exited.

Instructions:

This is a basic project that can be integrated into any Delphi project as a file manager. It includes some fundamental functions such as copying, deleting, moving, and renaming. The code can be extended or reduced as needed. The project can also assign access rights to the user, which are currently disabled in the code. This is for good reason, as the code can grant or deny access rights. Therefore, it's important to familiarize yourself with this to avoid accidentally locking folders or entire hard drives.

Main functions and tasks:

  • Navigation: Browsing directories and file systems using a graphical user interface (GUI).
  • File management: Performing basic operations such as copying, moving, deleting, and renaming files and folders.
  • Creation: Creating new folders and files.
  • Managing external storage media: Accessing and organizing data on external drives, such as USB sticks or external hard drives.
  • Metadata editing: Changing file properties such as attributes or permissions.

This is a dual-pane file manager, where the file is navigated on the left and execution is performed on the right.

ShellTreeView & ShellListView

Here, ShelTreeView and ShellListview operate in combination as a standalone file browser—though it should be noted that the primary focus lies on the visualization of files. Most functions are available and operate identically to those in Windows Explorer.

The file browser can be controlled via three components: the ShellTreeView, the ShellListView, and the address bar at the top.

The components are included with the project and must be installed.

For quite some time now, the TShellTreeView module has no longer been installed in the Components Palette by default in many versions of Delphi (e.g., Starter Editions starting with 10.2, as well as newer RAD Studio editions).

However, the source code remains integrated into your Delphi installation. You can manually install the component as follows:

Instructions:

  • Copy Source Code Files: In the Delphi installation directory, locate the files Vcl.Shell.ShellConsts.pas and Vcl.Shell.ShellCtrls.pas. (Default path: C:\Program Files (x86)\Embarcadero\Studio\[Version Number]\source\vcl) Copy these two files to a separate working directory.
  • Create and compile package:
    • Open your Delphi IDE.
    • Go to File > New > Package - Delphi and save it as ShellControls.bpl.
    • Add the two copied .pas files to the package using the Project Manager.
  • Add Registration Procedure:
    • Open the file Vcl.Shell.ShellCtrls.pas in your editor and add procedure Register; as the last line in the interface section. Insert the following code at the very top of the implementation section:
pascal
procedure Register;
begin
  RegisterComponents('Shell Controls', [TShellListView]);
  RegisterComponents('Shell Controls', [TShellTreeView]);
  RegisterComponents('Shell Controls', [TShellChangeNotifier]);
end;
  • Installing the Package: In the Project Manager, right-click on the package project and select Build. Next, right-click on the package and select Install. The components TShellTreeView, TShellListView, and TShellChangeNotifier will then be available to you in the "Shell Controls" category.

Restriction

However, there are limitations—such as cutting and moving files—that are not supported by the component.

The standard TShellListView component in Delphi does not natively feature built-in copy-and-paste functionality for Windows Explorer actions. The component serves primarily as a pure display of the file system.

To replicate the file copying, cutting, and pasting functionality found in Windows Explorer, you must interact with the native Windows Shell interfaces (IShellFolder and IContextMenu).

The Solution: Tapping into the Windows Shell Context Menu. Through the IContextMenu interface, you can directly instruct Windows to execute system-wide commands—such as 'copy', 'cut', or 'paste'—on the current directory. This allows Windows to automatically handle clipboard interactions, progress dialogs, and any potential file conflicts. Here is a proven method for implementing these commands within your TShellListView:

Code Example Cut-Paste

pascal
uses
    ActiveX, ShlObj, ShellAPI;

procedure ExecuteShellCommand(const ShellListView: TShellListView; const Command: string);
var
  ParentFolder: IShellFolder;
  ContextMenu: IContextMenu;
  InvokeInfo: TCMInvokeCommandInfo;
  Pidl: PItemIDList;
  Cidls: PItemIDList;
  ItemCount: Integer;
begin
  // Get the parent shell folder of the current directory.
  ParentFolder := ShellListView.Folder.ShellFolder;
  if ParentFolder = nil then Exit;
  ItemCount := ShellListView.SelCount;
  if (Command = 'paste') or (ItemCount = 0) then
  begin
    // For "Paste," or if nothing is selected, we use the folder itself.
    if Succeeded(ParentFolder.GetUIObjectOf(ShellListView.Handle, 0, Pidl, IID_IContextMenu, nil, Pointer(ContextMenu))) then
    begin
      ZeroMemory(@InvokeInfo, SizeOf(InvokeInfo));
      InvokeInfo.cbSize := SizeOf(TCMInvokeCommandInfo);
      InvokeInfo.hwnd := ShellListView.Handle;
      InvokeInfo.lpVerb := PAnsiChar(AnsiString(Command));
      ContextMenu.InvokeCommand(InvokeInfo);
    end;
  end;
end;