[英]Executing external exe in a child window (C++, win32)
I have written a simple win32 program say abc.exe
.我写了一个简单的win32程序,比如
abc.exe
。
I have added a button in it, clicking on which an external exe say xyz.exe
should start.我在其中添加了一个按钮,单击外部exe说
xyz.exe
应该启动的按钮。
But the original program ie abc.exe
should be inaccessible while xyz.exe
is running.但是当
xyz.exe
运行时,原始程序即abc.exe
应该是不可访问的。 (Same as in the case of message box where the parent window remains inactive unless message box is closed) (与消息框的情况相同,除非消息框关闭,否则父窗口保持不活动状态)
How can Ido it ?我该怎么做 ? It would be great if you could post an example code.
如果您可以发布示例代码,那就太好了。
You can use WaitForSingleObject
(IIRC) to wait for the new process to terminate.您可以使用
WaitForSingleObject
(IIRC) 来等待新进程终止。 You can make your window not visible (eg via ShowWindow
) before waiting.您可以在等待之前使您的窗口不可见(例如通过
ShowWindow
)。 Check successful launch first.首先检查成功启动。
When the button is pressed, create the 'xyz.exe' process using CreateProcess
function and save the new process' handle ( hProcess
in the PROCESS_INFORMATION
struct you passed in CreateProcess
).按下按钮后,使用
CreateProcess
函数创建“xyz.exe”进程并保存新进程的句柄(在CreateProcess
传递的PROCESS_INFORMATION
结构中的hProcess
)。
Then you can disable the 'abc.exe' window by calling EnableWindow
with bEnable
set to FALSE
.然后,您可以通过调用
EnableWindow
并将bEnable
设置为FALSE
来禁用“abc.exe”窗口。 In the window procedure of 'abc.exe', where the WM_PAINT
message is handled add a check to see if the 'xyz.exe' process is still running.在处理
WM_PAINT
消息的“abc.exe”窗口过程中,添加检查以查看“xyz.exe”进程是否仍在运行。 You can do this by using GetExitCodeProcess
function with the handle you saved earlier and checking if the return value is STILL_ACTIVE
.您可以通过将
GetExitCodeProcess
函数与您之前保存的句柄一起使用并检查返回值是否为STILL_ACTIVE
。 If the 'xyz.exe' process is no longer active, you can then enable the 'abc.exe' window using EnableWindow
again.如果“xyz.exe”进程不再处于活动状态,您可以再次使用
EnableWindow
启用“abc.exe”窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.