Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Windows Explorer Folder Popup Add Your Delphi Application Item to Windows Folder Shell Menu

Title: Windows Explorer Folder Popup - Add Your Delphi Application Item to Windows Folder Shell Menu Here's a neat trick to add an item to the right-click context popup menu for a folder in Windows Explorer. 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); begin with TRegistry.Create do try RootKey := HKEY_CLASSES_ROOT; if OpenKey('Directory\shell', true) then begin if OpenKey(itemName+'\command', true) then WriteString('', '"'+Application.ExeName+'" "%1"'); end; finally Free; end; end; The above code ensures there's the following entry in the Registry (note that "itemName" is a string parameter in EnsureShellFolderPopupItem): HKEY_CLASSES_ROOT\Directory\shell\itemName @="c:\...\myapplication.exe" "%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); begin //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(ParamStr(1)) else ShowMessage('APP started directly'); end; 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).