C ++的Win32 API删除与进度条的文件 [英] C++ Win32 API Delete file with progress bar

查看:872
本文介绍了C ++的Win32 API删除与进度条的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows API,是有什么办法可以删除一个较大的文件(可以说1GB +),并监控进度不知何故?我敢肯定它的可能的,但我不知道从哪里开始。

Using the windows api, is there any way to delete a large file (lets say 1gb+), and monitor the progress somehow? I'm sure its possible but I have no idea where to start..

编辑:本来应该更具体,我想将文件移动到回收站,并显示类似于探索一个进度条,但我可能要在控制台或什么的进度条,所以我不想要一个确切的复制品。

Should have been more specific, I want to move the file to the recycle bin, and show a progress bar similar to explores, though I might want the progress bar in a console or something so I don't want an exact replica.

编辑2:Yeaah猜测它是即时的,之前我问的问题应该有测试。
反正只要关闭这个问题?

EDIT 2: Yeaah guess it is instant, should have tested before I asked the question. Anyway to just close this question?

推荐答案

使用 SHFileOperation与 FO_DELETE FUNC和 FOF_ALLOWUNDO 标志的将文件移动到回收站。进展情况将自动显示,除非您还指定FOF_SILENT。

Use SHFileOperation with the FO_DELETE func and FOF_ALLOWUNDO flag to move a file to the Recycle Bin. Progress will automatically be shown unless you also specify FOF_SILENT.

SHFILEOPSTRUCT fileop = { 0 };
fileop.hwnd = hwndMain; /* your window */
fileop.wFunc = FO_DELETE;
fileop.pFrom = szFilePathToDelete;
fileop.fFlags = FOF_ALLOWUNDO /* | FOF_NOCONFIRMATION to recycle without prompting */;
int error = SHFileOperation(&fileop);

更新:作为的问题编辑指出,进展将不会显示一个文件,但它会当需要回收的整个目录显示。这还没有让你重写UI(例如,在控制台窗口中显示进度)。

Update: As noted in the question edit, progress won't be shown for a single file, but it will be shown if recycling an entire directory. This also doesn't let you override the UI (e.g., to display progress in a console window).

这篇关于C ++的Win32 API删除与进度条的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆