//我用以下代码可以实现移动文件,但不能在资源管理器中撤消该操作,FOF_ALLOWUNDO参数貌似没有作用...
TCHAR source[] = "C:\\files\\1.txt\0C:\\files\\2.txt\0";
TCHAR target[] = "D:\\files\0";

SHFILEOPSTRUCT fos;

ZeroMemory(&fos, sizeof(SHFILEOPSTRUCT));

fos.hwnd = m_hWnd;
fos.wFunc = FO_MOVE;
fos.pFrom = source;
fos.pTo = target;
fos.fFlags = FOF_NOCONFIRMMKDIR | FOF_ALLOWUNDO;
fos.fAnyOperationsAborted = TRUE;
fos.lpszProgressTitle = NULL;

::SHFileOperation(&fos);

解决方案 »

  1.   

    FOF_ALLOWUNDO
    Preserve undo information, if possible.
    Prior to Windows Vista, operations could be undone only from the same process that performed the original operation.In Windows Vista and later systems, the scope of the undo is a user session. Any process running in the user session can undo another operation. The undo state is held in the Explorer.exe process, and as long as that process is running, it can coordinate the undo functions.If the source file parameter does not contain fully qualified path and file names, this flag is ignored.貌似,vista之前的不可以
    不过有个hack办法,注入一个dll到explorer.exe去,然后在里面执行SHFileOperation...
      

  2.   

    一种可能的方法RE: Undoing a delete after SHFileOperation with the FOF_ALLOWUNDO flag     
    Hello Chris,
    When we call SHFileOperation with FO_DELETE and FOF_ALLOWUNDO, and if you did not disable the recycle bin function, 
    the file/folder will be moved to the hiden recycle bin folder of the drive. 
    From your description, what you want to do is to pull the file back from recycle bin. If I understand correctly,  you may use try 
    following way to restore the file: 
    1> retrieve recyclebin folder's pidl by using SHGetFolderLocation(CSIDL_BITBUCKET)
    2> bind the recycle bin pidl to an IShellFolder interface 
    3> enum the virtual folder through IShellFolder and find the file/folder you want to restore
    4> bind the interface to the file and query IContextMenu interface
    5> then invoke the "restore" command for the file/folder In addition, for steps1>and2> you can also find the recycle bin's IShellFolder interface directly from desktop folder. Thanks,
    Rhett Gong [MSFT]
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp&SD=msdn 
      

  3.   

    谢谢,貌似vista之前的系统不可以撤消有哪位朋友可以在vista上测试一下上面的代码2楼的方法不太明白,请教一下怎样使用的
      

  4.   

    楼主,::SHFileOperation(&fos);撤消该操作失败,错误代码是什么,自己查下或者贴出来,一起分析先!