#include <stdio.h>
#include <windows.h>
int main()
{
char strsrc[]="d:\\123.txt\0\0";
SHFILEOPSTRUCT lpfileop;
lpfileop.hwnd=NULL;
lpfileop.wFunc=FO_DELETE;
lpfileop.pFrom=strsrc;
lpfileop.pTo=NULL;
lpfileop.fFlags=FOF_ALLOWUNDO;
lpfileop.hNameMappings=NULL;
lpfileop.fAnyOperationsAborted=0;
int nok=SHFileOperation(&lpfileop);
if(nok) printf("出现了错误\n");else printf("文件被成功删除到了回收站\n");
return 0;
}
/*
delphi7下能够成功运行的代码
procedure TForm1.Button1Click(Sender: TObject);
var
lpFileOp: TSHFileOpStruct;
begin
lpFileOp.Wnd := Application.Handle;
lpFileOp.wfunc := FO_DELETE;
lpFileOp.pFrom := pchar('d:\123.txt');
lpFileOp.fFlags := FOF_ALLOWUNDO;
lpFileOp.hNameMappings :=nil;
lpFileOp.lpszProgressTitle :=nil;
lpFileOp.fAnyOperationsAborted :=false;
SHFileOperation(lpFileOp);
end;
*/