提取 SFX 存档时显示进度条

发布于 2024-09-01 22:46:50 字数 142 浏览 3 评论 0原文

我正在使用 C++ 和本机 Win32 API 编写一个程序。我正在静默模式下从 SFX 存档 EXE 创建一个进程,不会向用户显示任何 GUI。但我想在提取 SFX 存档时在我的应用程序中显示一个进度条。

我怎样才能做到这一点?

谢谢。

I'm writing a program with C++ and by native Win32 API. I'm creating a process from a SFX archive EXE in silent mode that no GUI is shown to user. But I want to show a progress bar in my application, while the SFX archive extracting.

How can I do that?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海未深 2024-09-08 22:46:51

如果您创建的进程产生一些文本输出到标准输出,那么您可能可以以某种方式解析该输出并显示进度。要知道它是否有效,请在命令行窗口中激活它并观察从中获得的结果。

win32 的 CreateProcess() 允许您将进程的标准输出重定向到管道。这样您就可以在生成后立即收到输出。

如果您正在创建的流程没有以某种方式报告其进度,那么您实际上无能为力。您可以尝试在文件大小和提取文件所需的平均时间之间找到函数,然后伪造一个进度条。这将起到让用户放心的目的,但仅此而已。

--编辑
一旦进程创建,对 CreateProcess() 的调用就会返回。 CreateProcess() 使用它创建的进程的句柄填充结构体PROCESS_INFORMATION。它包含进程主线程的句柄。如果您想等待进程完成,您可以在该线程句柄上使用WaitForSingleEvent(),该句柄在线程终止时会收到信号。使用完这些句柄后,不要忘记 CloseHandle() 这些句柄。

If the process you create produces some textual output to the standard output then you can probably parse that output somehow and show the progress. To know if it does, activate it in a command line windows and watch what you get from it.

win32's CreateProcess() allows you to redirect the standard output of the process to a pipe. This way you can receive the output as soon as it is produced.

If the process you're creating doesn't report its progress somehow then there's really not much you can do. You can try to come up with function between the size of the file and the average time it takes to extract it and then fake a progress bar. That will serve the purpose of setting the user's mind at ease but nothing more.

--Edit
The call to CreateProcess() returns as soon as the process is created. CreateProcess() fills up the struct PROCESS_INFORMATION with the handles of the process it creates. it contains the handle of the main thread of the process. If you want to wait for the process to finish you can WaitForSingleEvent() on that thread handle which gets signaled when the thread terminates. Don't forget to CloseHandle() those handles when you're done with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文