Google Groups no longer supports new usenet posts or subscriptions. Historical content remains viewable.
Dismiss

placing shortcut on desktop

48 views
Skip to the first unread message

Martin

unread,
20 Mar 2007, 22:23:3620/03/2007
to

Hello -

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

NovaKane

unread,
20 Mar 2007, 23:36:1420/03/2007
to

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.

Rob Kennedy

unread,
20 Mar 2007, 23:46:3620/03/2007
to

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

Remy Lebeau (TeamB)

unread,
21 Mar 2007, 00:44:3221/03/2007
to

"Martin" <mn3...@earthlink.net> wrote in message
news:46008918$1...@newsgroups.borland.com...

> 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

http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_int/shell_int_programming/shortcuts/shortcut.asp


Gambit


Matt Lacey

unread,
21 Mar 2007, 10:52:3521/03/2007
to

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.

Martin

unread,
24 Mar 2007, 17:04:4024/03/2007
to

Actually, The IPersistFile and CreateComObject keep coming
back with undeclared identifier. I tried adding to the uses
but I've had no luck.

Liz

unread,
24 Mar 2007, 19:25:1424/03/2007
to
Martin wrote:

>
> 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

Rob Kennedy

unread,
24 Mar 2007, 19:20:4424/03/2007
to
Martin wrote:
> Actually, The IPersistFile and CreateComObject keep coming
> back with undeclared identifier.

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

Remy Lebeau (TeamB)

unread,
25 Mar 2007, 01:33:4825/03/2007
to

"Martin" <mn3...@earthlink.net> wrote in message
news:46058458$1...@newsgroups.borland.com...

> 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


Martin

unread,
30 Mar 2007, 23:32:5430/03/2007
to

Many thanks for all of the suggestions. The uses information
put me over the top. Sometimes the obvious just passes me by..

Martin

0 new messages