请问如何得到NT/2000下当前用户的桌面文件夹路径?(50分)

  • 主题发起人 主题发起人 小天
  • 开始时间 开始时间
function GetDesktopDir: string;
var
Buffer: PChar;
ItemIDList: PItemIDList;
ShellMalloc: IMalloc;
begin
Result := '';
if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then
begin
Buffer := ShellMalloc.Alloc(MAX_PATH);
try
if SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, ItemIDList) = S_OK then
if SHGetPathFromIDList(ItemIDList,Buffer) then
SetString(Result, Buffer, StrLen(Buffer));
finally
ShellMalloc.Free(Buffer);
end;
end;
end;
 
bbkxjy:你的程序段摘自哪里的啊?怎么没头没尾的
 
参考 FileCtrl.pas 的,要 uses shlobj 和 ActiveX 单元。
 
试了一下,下面的也行,也要引用 shlobj :
function GetDesktopFolder: string;
var
Buffer: PChar;
begin
Result := '';
GetMem(Buffer, MAX_PATH);
try
if ShGetSpecialFolderPath(Application.Handle,Buffer, CSIDL_DESKTOP, False) then
SetString(Result, Buffer, StrLen(Buffer));
finally
FreeMem(Buffer)

end;
end;
 
接受答案了.
 
后退
顶部