1. Home
  2. Computing & Technology
  3. Delphi Programming

Add your Application to the Windows "Send To" Menu
Adding a link to your application in the "Send To" menu and processing the file

By Zarko Gajic, About.com

Delphi application in 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:

  1. Create a shortcut to your application,
  2. Place it in the special Windows "Send To" folder,
  3. 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:
  1. Click Start, and then click Run
  2. In the Open box, type sendto, and then click OK.
  3. Use the drag-and-drop operation to move the item that you want to the SendTo folder.

Delphi tips navigator:
» How to Translate a Virtual Key Code to a Character
« Drawing a Focus Rectangle Around the Active Control

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2006 Tips
  7. Add your Delphi application to the Windows "Send To" menu

©2009 About.com, a part of The New York Times Company.

All rights reserved.