When a users right-clicks on a folder in Windows Explorer (and TShellTreeView not to forget) a context popup appears. Beside standard items you can add an item for your application. When a user click the item - your application gets started and you can send it (as a parameter) the folder selected.
The EnsureShellFolderPopupItem procedure adds an entry in the Windows registry to start the application.
procedure EnsureShellFolderPopupItem(const itemName : string);The above code ensures there's the following entry in the Registry (note that "itemName" is a string parameter in EnsureShellFolderPopupItem):
with TRegistry.Create do
RootKey := HKEY_CLASSES_ROOT;
if OpenKey('Directory\shell', true) then
if OpenKey(itemName+'\command', true) then
WriteString('', '"'+Application.ExeName+'" "%1"');
"c:\...\myapplication.exe" is the actual location of your Delphi application executable.
The OnCreate of a form gets the passed parameter and displays the folder path for the selected folder.
procedure TSomeForm.FormCreate(Sender: TObject);Not sure what application parameters are and how to process parameters in your application? Here's more info: Running Delphi Applications With Parameters, Parsing Command Line Parameters with Delphi, How to Run your Application by Double-Clicking on a File (Register Extension).
//make sure there is our item in shell folder's popup menu
//not needed to call this every time but for testing ok ....
EnsureShellFolderPopupItem('Process with my application');
//show what folder has been selected to process
if ParamCount > 0 then
ShowMessage('APP started directly');