Peter Bönnen
Erfahrenes Mitglied
Hallo,
Hoffe, es hilft.
Peter
...Use:
var
PIDL: PItemIDList;
Buffer: array[0.2569 of Char;
SHGetSpecialFolderLocation(0, CSIDL_SENDTO, PIDL);
SHGetPathFromIDList(PIDL, Buffer);
to get the file name of the "Send To" folder. Then use
ChDir(Buffer);
MkDir('your folder here');
to create the new folder. Concatenate the "Send To" folder string and your new name to a valid path and use this to place links in.
Quelle: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10226500.htmlSnoopy, some additional comments. The buffer declaration should of course be:
Buffer: array[0..MAX_PATH] of Char;
You need also to retrieve a shell allocator to free the PIDL memory you got by SHGetSpecialFolderLocation:
var
Malloc: IMalloc;
begin
SHGetMalloc(Malloc);
:
:
Malloc.Free(PIDL);
end;
You don't need to free Malloc as this is an interface which is automatically free when it gets out of scope (the routine).
To create a link in a folder use:
function MakeLinkWithArguments(Name, Folder, ExeName, WorkingDir, Argument: String): Integer;
// Name: name of the link without the ".lnk"
// Folder: folder where the link should be placed in
// ExeName: filename and path of the executable (can also be a document etc.)
// WorkingDir: working directory of the program
// Argument: all arguments for the link, note: if there are spaces in an argument then it should be surrounded with ""
var
AObject: IUnknown;
ASLink: IShellLink;
APFile: IPersistFile;
WFileName : WideString;
R: HRESULT;
begin
Result := erOK;
AObject := CreateComObject(CLSID_ShellLink);
ASLink := AObject as IShellLink;
APFile := AObject as IPersistFile;
with ASLink do begin
SetArguments(PChar(Argument));
SetPath(PChar(ExeName));
SetWorkingDirectory(PChar(WorkingDir));
end;
if not DirectoryExists(Folder) then Result := erDirectory;
if (Length(Name) > 0) and (Name[Length(Name)] = '\') then Delete(Name, Length(Name), 1);
WFileName := Folder + '\' + Name + '.lnk';
R := APFile.Save(PWChar(WFileName), False);
if R = E_FAIL then Result := Result or erFile;
end;
Placing a new folder into the shell's context menu is somewhat harder as you have to write a context menu handler I guess. Unfortunately, I cannot tell you how to add another folder...
Hoffe, es hilft.
Peter