简体   繁体   English

Windows C ++将启动的子进程置于前台

[英]Windows C++ bring launched child process to foreground

I am launching a child process via CreateProcess API. 我正在通过CreateProcess API启动子进程。 However, because it takes some time to start up and show its main window, its possible for the user to click elsewhere in the parent window while this is happening. 但是,由于启动和显示其主窗口需要花费一些时间,因此在这种情况下,用户可以单击父窗口中的其他位置。 The child window then goes to the background. 子窗口然后转到后台。 How would I get it back into the foreground from the parent process? 我如何将其从父进程中放回前台?

You don't, the user decided that she was tired of waiting and wanted to work with a responsive program. 并非如此,用户认为她已经厌倦了等待,并希望使用响应程序。 Review the fine print in SetForegroundWindow() for all the reasons that trying to find a workaround for this won't actually work. 出于所有无法找到解决方法的原因,请查看SetForegroundWindow()中的详细信息。 Make sure she can get back to the program when it is initialized, a taskbar button is key. 确保程序初始化后她可以返回程序,任务栏按钮是关键。

I've used SetWindowPos() for this in the past. 我过去曾使用SetWindowPos()。 It's kind of a swiss army knife, it can move and resize windows, as well as change their z-order position. 这是瑞士军刀,它可以移动和调整窗口大小以及更改其z顺序位置。 You just want to change its z-order to HWND_TOP. 您只想将其z顺序更改为HWND_TOP。

SetActiveWindow()过去也为我工作,我推荐它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM