shortcut no desktop

22/05/2003

1

gostaria de saber como criar um shortcut da minha aplicacao no desktop, através do delphi... alem disso, como criar um grupo de programas e dentro deste outro shortcut p minha aplicacao. obrigado.


Responder

Posts

22/05/2003

Will

procedure CriarLink(const FileName, DisplayName: string; Folder: Integer; SubDirectory: string);
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
ItemIDList: PItemIDList;
FileDestPath: array[0..MAX_PATH] of Char;
FileNameW: array[0..MAX_PATH] of WideChar;
begin
CoInitialize(nil);
try
OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_SERVER,
IID_IShellLinkA, ShellLink));
try
OleCheck(ShellLink.QueryInterface(IID_IPersistFile, PersistFile));
try
OleCheck(SHGetSpecialFolderLocation(0, Folder, ItemIDList));
SHGetPathFromIDList(ItemIDList, FileDestPath);
if SubDirectory <> ´´ then
StrCat(FileDestPath, PChar(´\´ + SubDirectory + ´\´ + DisplayName + ´.lnk´))
else
StrCat(FileDestPath, PChar(´\´ + DisplayName + ´.lnk´));
ShellLink.SetPath(PChar(FileName));
ShellLink.SetWorkingDirectory(PChar(ExtractFileDir(FileName)));
ShellLink.SetIconLocation(PChar(FileName), 0);
MultiByteToWideChar(CP_ACP, 0, FileDestPath, -1, FileNameW, MAX_PATH);
OleCheck(PersistFile.Save(FileNameW, True));
finally
PersistFile := nil;
end;
finally
ShellLink := nil;
end;
finally
CoUninitialize;
end;
end;

// Para criar no Desktop utilize o exemplo
CriarLink(´C:\MeuPrograma.exe´, ´Meu Programa´, CSIDL_DESKTOPDIRECTORY, ´´);
// Para criar no Menu Iniciar utilize o exemplo
CriarLink(´C:\MeuPrograma.exe´, ´Meu Programa´, CSIDL_PROGRAMS, ´Minha Empresa´);


Responder