//我用以下代码可以实现移动文件,但不能在资源管理器中撤消该操作,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);
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);
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...
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