在 WIN32 上结合 CreateProcess 和 AllowSetForegroundWindow

发布于 2024-12-18 04:16:44 字数 1391 浏览 1 评论 0原文

我有一个应用程序,本质上是一个包装另一个应用程序的“助手”应用程序。

用户与之交互的应用程序是由“帮助程序”应用程序创建的进程,如下所示:

PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
memset(&processInfo, 0, sizeof(processInfo));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
startupInfo.cb = sizeof(startupInfo);
int retval = CreateProcess(cmd, cmdLine, NULL, NULL, false,
    CREATE_NO_WINDOW, NULL, NULL, &startupInfo,
    &processInfo);

该进程是一个可执行文件,我没有源代码,也无法对其进行更改。

“助手”应用程序主要根据来自其他应用程序的网络流量执行一些操作。在某一时刻,我想根据用户在启动的 UI 进程中执行的操作,从帮助程序应用程序中显示一个文件浏览对话框。

当我从帮助程序应用程序显示文件对话框时,它显示在所创建进程的 UI 后面,这并不理想。我尝试从帮助程序应用程序调用 SetForegroundWindow() ,但它不符合 MSDN 文档中为 SetForegroundWindow 指定的条件( http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx ),即:

该进程不是前台进程。

该进程不是由前台进程启动的。

(即使该进程创建了前台进程)。

有没有一种方法可以使用标志或设置来调用 CreateProcess() ,其工作方式类似于从该进程中调用AllowSetForegroundWindow() ?或者一个可以用来让 Windows 认为启动的进程与出于 SetForegroundWindow 权限而启动它的进程“相同”的标志?

或者是否有另一种方法可以在创建的进程的对话框之上显示帮助程序应用程序生成的对话框?

I have an application that is essentially a "helper" application that wraps another app.

The app that the user interacts with is a process that is created by the "helper" app like so:

PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
memset(&processInfo, 0, sizeof(processInfo));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startupInfo.dwFlags = STARTF_USESTDHANDLES;
startupInfo.cb = sizeof(startupInfo);
int retval = CreateProcess(cmd, cmdLine, NULL, NULL, false,
    CREATE_NO_WINDOW, NULL, NULL, &startupInfo,
    &processInfo);

This process is an executable that I do not have the source code to and cannot make changes to.

The "helper" application does a few things based mainly on network traffic from the other app. At one point I want to display a file browse dialog from the helper app based on something the user does in the started UI process.

When I show the file dialog from the helper app, it's shown behind the UI of the process that was created, which isn't ideal. I tried calling SetForegroundWindow() from the helper app but it fails the criteria specified for SetForegroundWindow in the MSDN docs ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx ), namely:

The process is not the foreground process.

The process was not started by the foreground process.

(even though the process created the foreground process).

Is there a way to call CreateProcess() with a flag or setting that works like calling AllowSetForegroundWindow() from that process? Or a flag that can be used to make Windows think the started process is "the same" as the process that started it for purposes of SetForegroundWindow permissions?

Or is there another way I can show the dialog generated by the helper app on top of the created process' dialogs?

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

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

发布评论

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

评论(1

愚人国度 2024-12-25 04:16:44

我能想到的唯一解决方案是对子进程进行远程线程注入,然后让注入的线程使用适当的参数调用 AllowSetForegroundWindow 以允许父进程偷回前景。

不过我还没有测试过。

The only solution I could think of off the top of my head would be to do remote thread injection into the child process, and then have your injected thread call AllowSetForegroundWindow with the appropriate parameters to allow the parent process to steal foreground-ness back.

I have not tested this though.

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