Mega Code Archive

 
Categories / Delphi / System
 

Add your Delphi application to the Windows Send To menu

Title: Add your Delphi application to the Windows "Send To" menu If you have registered your own file type (extension) for an application, you can tell Windows to start your application when a user double clicks the file (or selects "Open" from the context popup menu) in the Windows Explorer. Another approach to allowing the user to send a file to your application for processing, without the need to register a file type, is to add your application to the special Windows "Send To" menu. The "Send To" appears as an item in the context menu when you, for example, right click on a file in the Windows Explorer. By using the Send To command, you can quickly send a file to different locations including a floppy disk, your desktop, another person using e-mail, or the My Documents folder. The SendTo folder contains the shortcuts for the destinations that are displayed on the Send To menu. Every user on the computer has a SendTo folder and can customize its contents. Here's how to place a shortcut to your Delphi application to the Send To menu: Create a shortcut to your application, Place it in the special Windows "Send To" folder, When your application is activated, process the file being "sent". Creating a shortcut and placing it in the special "Send To" Windows menu can be done in one step: procedure CreateShortcutIn(const SpecialFolderCSIDL: integer; const shortcutName : string) ; var IObject : IUnknown; ISLink : IShellLink; IPFile : IPersistFile; PIDL : PItemIDList; InFolder : array[0..MAX_PATH] of Char; TargetName : String; LinkName : WideString; begin TargetName := ParamStr(0) ; IObject := CreateComObject(CLSID_ShellLink) ; ISLink := IObject as IShellLink; IPFile := IObject as IPersistFile; with ISLink do begin SetPath(pChar(TargetName)) ; SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ; end; //get the location of the "special folder" SHGetSpecialFolderLocation(0, SpecialFolderCSIDL, PIDL) ; SHGetPathFromIDList(PIDL, InFolder) ; LinkName := Format('%s\%s.lnk',[InFolder, shortcutName]) ; IPFile.Save(PWChar(LinkName), false) ; end; Usage: //CSIDL_SENDTO = "Send TO" special folder CreateShortcutIn(CSIDL_SENDTO,'My Delphi Application') ; Processing the file sent to the application in the form's OnCreate event handler: procedure TMainForm.FormCreate(Sender: TObject) ; begin //get the file that was "send to" this application if ParamCount 0 then ShowMessage(ParamStr(1)) ; end; Note: to manually add a destination to the Send To menu, you must add a shortcut to the SendTo folder. To do this, follow these steps: Click Start, and then click Run In the Open box, type sendto, and then click OK. Use the drag-and-drop operation to move the item that you want to the SendTo folder.