如何 用 winapi 函数 调用回收站(100分)

  • 主题发起人 主题发起人 usergcj
  • 开始时间 开始时间
U

usergcj

Unregistered / Unconfirmed
GUEST, unregistred user!
如何 用 winapi 函数 调用回收站
 
procedure TForm1.ToRecycle(AHandle: THandle; const ADirName: string);<br>var<br>&nbsp; SHFileOpStruct: TSHFileOpStruct;<br>&nbsp; DirName: PChar;<br>&nbsp; BufferSize: Cardinal;<br>begin<br>&nbsp; BufferSize := Length(ADirName) + 1 + 1;<br>&nbsp; GetMem(DirName, BufferSize);<br>&nbsp; try<br>&nbsp; &nbsp; FillChar(DirName^, BufferSize, 0);<br>&nbsp; &nbsp; StrCopy(DirName, PChar(ADirName));<br><br>&nbsp; &nbsp; with SHFileOpStruct do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Wnd := AHandle;<br>&nbsp; &nbsp; &nbsp; &nbsp; wFunc := FO_DELETE;<br>&nbsp; &nbsp; &nbsp; &nbsp; pFrom := DirName;<br>&nbsp; &nbsp; &nbsp; &nbsp; pTo := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; fFlags := FOF_NOCONFIRMATION;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; hNameMappings := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; lpszProgressTitle := nil;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; if SHFileOperation(SHFileOpStruct) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(DirName, BufferSize);<br>&nbsp; end;<br>end;<br>
 
清空回收占:<br>SHEmptyRecycleBin<br>这个函数和其他一些函数没有被delphi声明<br>必须自己从shell32.dll中声明<br>文件删除到回收占:<br>uses ShellApi;<br>{ 利用ShellApi中: function SHFileOperation(const lpFileOp: TSHFileOpStruct): Integer; stdcall; }<br><br>Var T:TSHFileOpStruct;<br>P:String;<br>begin<br>P:='C:/Windows/System/EL_CONTROL.CPL';<br>With T do<br>Begin<br>Wnd:=0;<br>wFunc:=FO_DELETE;<br>pFrom:=Pchar(P);<br>fFlags:=FOF_ALLOWUNDO<br>End;<br>SHFileOperation(T);<br>End.<br><br>注意:<br>1. 给出文件的绝对路径名,否则可能不能恢复;<br>2. MS的文档说对于多个文件,每个文件名必须被#)字符分隔,而整个字符串<br>必须用两个#0结束。<br>
 
后退
顶部