ShellPlus Customer login
ShellPlus
Shell+ components
    Home
    News
    Overview
    Download
    Examples
    Customer's area
    Flash Demo
 
Developer Tools
    Shell Reset Tool
 
Shell+ Tutorial
    Namespace Extensions
    ShortCut menu
    Property Sheet
    Icon Handler
    Thumbnails
    InfoTip Handler
    Copy Hook
    Balloon TrayIcon
    Control Panel
    Shortcut Files
    Drag&Drop Menu
    Shell Change Notify
 
 
Documents
    Articles Index
    Press Releases
 
Purchase
    Buy now
    Resellers network
    Resellers wanted
 
Support
    Contact directly
    Customer's area
 
About/Contacts
    Shell+ Developers

Embarcader Technology Partner

 
ShellLink Component Example

    Shortcut creation is a common task for Windows programmers. The TSxWinShellLink component makes shortcut handling as easy as possible. Follow the example below to learn how easy to use it.

    This example uses TSxWinShellLink to implement tiny shortcut editor. This editor is even more powerful that native Windows "Create shortcut" tool. Namely it allows to assign hotkey for the shortcut on the desktop while native shortcut editor does not support this feature.

    Create a new application: File -> New... -> Application. Place a few controls onto its main form as shown on the figure below. Don't forget to add the TSxWinShellLink component:

Windows Shell Link Example

    Save the project now.

    The next step is to set TSxWinShellLink properties. Use the values from the table below to configure the component:

PathFlag This flag defines the format of the file path. The pfRawPath is used in this example. It means that the raw path name will be used. A raw path is something that might not exist and may include environment variables that need to be expanded.
STGM

Use this record to control the link file access method. Set its members as follows:
• Access = stgmReadWrite
• Creation = stgmCreate
• Sharing = stgmShareDenyNone
• Transactioning = stgmDirect

Other record members are not used to deal with the shortcut.


(Note: this table contains description of properties that will be used in this example. Please refer the online help to learn about other component properties)

    Set the event handlers now. The OnCreate event for the form is:

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShellLink.New;
end;

     The OnClick event handler for the "NewLink" button is:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellLink.New;
end;

     The "LoadLink" button has the following OnClick handler:

procedure TForm1.Button2Click(Sender: TObject);
begin
  if OpenDialog.Execute then
     ShellLink.LoadFromFile(OpenDialog.Filename);
  AssignValues;
end;

     The "SaveLink" button works as:

procedure TForm1.Button3Click(Sender: TObject);
begin
  ShellLink.Arguments:=eArguments.Text;
  ShellLink.Description:=eDescription.Text;
  ShellLink.HotKey:=eHotKey.HotKey;
  ShellLink.Modifiers:=eHotKey.Modifiers;
  ShellLink.IconLocationPath:=eIconLocation.Text;
  ShellLink.IconLocationIndex:=StrToInt(eIconIndex.Text);
  ShellLink.Path:=ePath.Text;
  ShellLink.ShowCmd:=TSxShowCmd(eShowCmd.ItemIndex);
  ShellLink.WorkingDirectory:=eWorkingDirectory.Text;
  if SaveDialog.Execute then
     ShellLink.SaveToFile(SaveDialog.Filename);
end;

     One more button - "Resolve" - is implemented as follows:

procedure TForm1.Button4Click(Sender: TObject);
begin
  if ShellLink.Resolve(Handle,[]) then
  begin
    AssignValues;
    ShowMessage('Resolve OK')
  end
  else
     ShowMessage('Resolve Failed');
end;

     The AssignValues procedure is used by handlers above. Implement it as:

procedure TForm1.AssignValues;
begin
  eArguments.Text:=ShellLink.Arguments;
  eDescription.Text:=ShellLink.Description;
  eHotKey.HotKey:=ShellLink.HotKey;
  eHotKey.Modifiers:=ShellLink.Modifiers;
  eIconLocation.Text:=ShellLink.IconLocationPath;
  eIconIndex.Text:=IntToStr(ShellLink.IconLocationIndex);
  ePath.Text:=ShellLink.Path;
  eShowCmd.ItemIndex:=Integer(ShellLink.ShowCmd);
  eWorkingDirectory.Text:=ShellLink.WorkingDirectory;
end;

    Save the project and compile it - it is ready now! Test it. Run it and press the "LoadLink" button. Select any acceptable file with a .lnk extension (it is a shortcut) and press the "OK". The shortcut file will be loaded and you will see its parameters. Now you can modify the shortcut parameters and save it.

Download example

Use links below to download source codes of this example as well as binary files:

Delphi 10.1 Berlin (x64)
ShellLink-D24X64.zip
19.12Kb
3.15.296.396
11.09.2016
Delphi 10.1 Berlin
ShellLink-D24.zip
15.87Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle (x64)
ShellLink-D23X64.zip
18.87Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle
ShellLink-D23.zip
15.51Kb
3.15.296.396
11.09.2016
Delphi XE8 (x64)
ShellLink-D22X64.zip
18.41Kb
3.12.289.357
15.05.2015
Delphi XE8
ShellLink-D22.zip
14.86Kb
3.12.289.357
15.05.2015
Delphi XE7 (x64)
ShellLink-D21X64.zip
18.20Kb
3.11.289.357
19.09.2014
Delphi XE7
ShellLink-D21.zip
14.73Kb
3.11.289.357
19.09.2014
Delphi XE6 (x64)
ShellLink-D20X64.zip
18.18Kb
3.10.287.331
16.09.2014
Delphi XE6
ShellLink-D20.zip
14.73Kb
3.10.287.331
16.09.2014
Delphi XE5 (x64)
ShellLink-D19X64.zip
17.02Kb
3.10.287.331
16.03.2014
Delphi XE5
ShellLink-D19.zip
14.59Kb
3.10.287.331
16.03.2014
Delphi XE4 (x64)
ShellLink-D18X64.zip
17.02Kb
3.10.287.331
16.03.2014
Delphi XE4
ShellLink-D18.zip
14.58Kb
3.10.287.331
16.03.2014
Delphi XE3 (x64)
ShellLink-D17X64.zip
17.02Kb
3.10.287.331
16.03.2014
Delphi XE3
ShellLink-D17.zip
14.53Kb
3.10.287.331
16.03.2014
Delphi XE2 (x64)
ShellLink-D16X64.zip
16.35Kb
3.10.287.331
16.03.2014
Delphi XE2
ShellLink-D16.zip
14.46Kb
3.10.287.331
16.03.2014
Delphi XE
ShellLink-D15.zip
11.36Kb
3.10.287.331
16.03.2014
Delphi 2010
ShellLink-D14.zip
11.20Kb
3.10.287.331
16.03.2014
Delphi 2009
ShellLink-D12.zip
10.52Kb
3.10.287.331
16.03.2014
Delphi 2007
ShellLink-D11.zip
10.38Kb
3.10.287.331
16.03.2014
Delphi 2006
ShellLink-D10.zip
10.33Kb
3.10.287.331
16.03.2014
Delphi 2005
ShellLink-D9.zip
11.63Kb
3.10.287.331
16.03.2014
Delphi 7
ShellLink-D7.zip
11.44Kb
3.12.289.357
16.05.2015
Delphi 6
ShellLink-D6.zip
11.31Kb
3.8.287.331
09.05.2012

  Top


Components | Download | Purchase | Support | About Us
Copyright © 2016 ALDYN Software. All rights reserved.
Copyright © 2001 - 2011 Shell+ Development Group. All rights reserved.