I am trying to place a shortcut on the desktop to call my
application which is located somewhere down the line in the
programs folder. I know how to use the Shellobj and actually
place the application on the desktop, but I want to leave the
app where it is and just put the shortcut on the desktop. I
also want to have the application icon be the shortcut icon on
the desktop. Any ideas? Thanks much.
Martin
Navigate to your app folder, right click on the EXE file, and choose
Send To...Desktop (create shortcut). That always works for me. If
you're on Vista, I don't know. :>) Whatever you're using for the app
icon, should show up as your shortcut icon also.
Which part is giving you trouble? Have you tried any of the sample code
you found when you searched the newsgroup archives? What have you tried,
and how has it failed?
http://groups.google.com/groups?q=shellobj+shortcut+desktop&as_ugroup=*delphi*
--
Rob
> I am trying to place a shortcut on the desktop
You need to use the IShellLink interface, as explained in the
following article:
Shell Links
Gambit
Don't do this in the program. Do it as part of the installation
process.
And even then only if the user requests the shortcut to be created.
>
> Actually, The IPersistFile and CreateComObject keep coming
> back with undeclared identifier. I tried adding to the uses
> but I've had no luck.
What version of delphi are you using, it all seems to work for me
I added ShlObj, ActiveX, ComObj to uses
and
procedure TForm1.FormCreate(Sender: TObject);
var IObject : IUnknown;
ISLink : IShellLink;
IPFile : IPersistFile;
PIDL : PItemIDList;
InFolder : array[0..MAX_PATH] of Char;
TargetName : String;
LinkName : WideString;
begin
TargetName := 'c:\windows\calc.exe';
{Use TargetName:=ParamStr(0) which
returns the path and file name of the
executing program to create a link to your
Application}
IObject := CreateComObject(CLSID_ShellLink) ;
ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile;
with ISLink do
begin
SetPath(pChar(TargetName)) ;
SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
end;
// if we want to place a link on the Desktop
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
SHGetPathFromIDList(PIDL, InFolder) ;
{
or if we want a link to appear in
some other, not-so-special, folder:
InFolder := 'c:\SomeFolder'
}
LinkName := InFolder + '\Delphi Created Link.lnk';
IPFile.Save(PWChar(LinkName), false) ;
end;
--
Liz the Brit
Delphi things I have released: http://www.xcalibur.co.uk/DelphiThings
That means you haven't included any unit that declares those identifiers.
> I tried adding to the uses
> but I've had no luck.
What have you tried adding? When I need to know what unit something is
declared in, I do a text search on the source code.
--
Rob
> Actually, The IPersistFile and CreateComObject keep
> coming back with undeclared identifier.
CreateComObject() is declared in the ComObj unit, and IPersistFile is
declared in the ActiveX unit.
Gambit
Many thanks for all of the suggestions. The uses information
put me over the top. Sometimes the obvious just passes me by..
Martin