如何用delphi 得到windows的桌面的路径?(100分)

  • 主题发起人 主题发起人 大师
  • 开始时间 开始时间

大师

Unregistered / Unconfirmed
GUEST, unregistred user!
想编程显示windows的桌面文件夹里的内容,<br>不知那位高手实现过?
 
如果是Win98<br>c:array[0..MAX_PATH]of char;<br>DeskDir:string;<br>....<br>GetWindowsDirectory(c,sizeof(c));<br>DeskDir:=strpas(c)+'/desktop';<br><br>如果是Win2000<br>在 Documents and Settings/文件夹中,估计得先得到用户名,有些麻烦。
 
楼上的,即使在Win9x下面,也不能采取你的方法!我的桌面就从来不在%WindDir%目录里面!<br><br>提示一下:ShGetSpecialFolderLocation() API,自己看帮助!
 
&nbsp; RootKey := HKEY_CURRENT_USER;<br>&nbsp; &nbsp;OpenKey('Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;false);<br>&nbsp; &nbsp; a:= ReadString('DeskTop');<br><br>读注册表,对98/2000都管用
 
bbkxjy (2001-6-11 16:50:00) &nbsp;<br>试了一下,下面的也行,也要引用 shlobj :<br>function GetDesktopFolder: string;<br>var<br>&nbsp; Buffer: PChar;<br>begin<br>&nbsp; Result := '';<br>&nbsp; GetMem(Buffer, MAX_PATH);<br>&nbsp; try<br>&nbsp; &nbsp; if ShGetSpecialFolderPath(Application.Handle,Buffer, CSIDL_DESKTOP, False) then<br>&nbsp; &nbsp; &nbsp; SetString(Result, Buffer, StrLen(Buffer));<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(Buffer); &nbsp; &nbsp;<br>&nbsp; end;<br>end; <br>&nbsp;<br>
 
后退
顶部