Summary

This article provides a step-by-step tutorial to create a context menu for the Windows Explorer using Delphi. This is called a Context Menu Shell Extension which provides functionality to the Windows Explorer when 'right-clicking' a file.

The figure beside shows the result of the coding: the MyShellExt - Main menu in the Windows Explorer with an icon and three sub-menus.

You need the Embarcadero Delphi programming environment. No special features or libraries are required.

You do not need special knowledge beside some basic knowledge how to create, compile and run a code in Delphi.

This tutorial will provide step-by-step guidance to generate and code a COM Object compiled into a Dynamic Link Library (DLL) which will hold the functions and code to make the Shell Extension. The tutorial will also give some guidance required to compile and register the DLL, and all necessary steps to un-register the DLL to be able to re-compile updated code.

Be careful: The Windows Explorer provides the full Windows view including the Desktop and Taskbar etc. The Shell Exension code could crash the Explorer and you basically loose the basic user Windows GUI functionality. If something goes completely wrong and the Explorer does not start anymore, start the Windows Task-Manager <Ctrl-Alt-Del> select Task-Manager, then start the Registry Editor by starting a new task <regedit>, and remove the registry key where the DLL is registered, like: HKEY_CLASSES_ROOT\*\shell\MyShellExt. After that you can restart the Explorer through the Task-Manager <explorer>.

 

Tutorial Structure

The tutorial is structured in the following parts to keep it easier for you to understand and follow the necessary steps. Part 1 is the most complex one as it provides all the necessary background to create an Active-X COM Object, how to register the produced DLL, and more cumbersome how to un-register the DLL to be able to re-compile the code.

Part 1 - Basic Context Menu

Part 1 addresses all fundamentals for a Shell Extension Context Menu and will provide two basic entries in the right-click menu for all files. In particular the following topics are addressed:

  • Create an Active-X COM Object from scratch
  • Delphi Compiler Options, in particular 64-bit selection
  • Register the DLL
  • Un-register the DLL and abiilty to delete/override the file
  • All Delphi coding required

Download Part 1

 

Part 2 - Select Multiple Files

Part 2 extends the code and functionality of the shell extension to be able to select multiple files.

Download Part 2

 

Part 3 - Create Sub-Menus

Part 3 extends the code and functionality of the shell extension to allow sub-menus and icons for our menu items.

Download Part 3

 

Part 4 - Bind to Particular File Extension

Part 4 extends the code and functionality of the shell extension to register it to a specific file extension. For instance .txt, or .dll files.

Download Part 4

 

Part 5 - Define Default Item

Part 5 extends the code and functionality of the shell extension to allow a sub-menu item to be the default item. This has 2 effects: 1) when double-clicking the MyShellExt item the default item is selected, and  and icons for our menu items; 2) the default item is shown in bold text

Download Part 5