使用Delphi的ShellExecute()与继承原始控制台的进程?
在 C 中,我之前在控制台应用程序中使用过 system() 函数,如果我使用 system() 启动另一个进程,它会继承调用该函数的进程的控制台窗口它。
在 Delphi 中,system()
不存在,因此我使用 ShellExecute()
创建一个新进程,但新进程出现在新的控制台窗口中。有什么方法可以让它继承调用它的窗口的句柄吗?
我曾经
function GetConsoleWindow(): HWND; stdcall; external 'kernel32.dll';
获取控制台窗口并将其传递到 ShellExecute()
的 HWND
部分,但这不起作用。
In C I've used the system()
function before in a console application and if I start another process using system()
it inherits the console window of the process that called it.
In Delphi system()
doesn't exist so I'm using ShellExecute()
to create a new process, but the new process comes up in a new console window. Is there some way that I can make it inherit the handle of the window that's calling it?
I've used
function GetConsoleWindow(): HWND; stdcall; external 'kernel32.dll';
to get the console window and passed it in the HWND
part of ShellExecute()
, but that didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 ShellExecute() 您将无法使生成的应用程序使用相同的控制台。
ShellExecute()
调用中的HWND
元素已记录:所以它不会对控制台应用程序产生任何影响。
如果您使用
CreateProcess()
相反,您对生成的进程有更多的控制权。通过使用dwCreationFlags
参数,您可以强制新进程获取自己的控制台(使用CREATE_NEW_CONSOLE
标志),但默认情况下它也会继承父进程的控制台。Using
ShellExecute()
you won't be able to make the spawned application use the same console. TheHWND
element in theShellExecute()
call is documented:so it won't have any effect for console applications.
If you use
CreateProcess()
instead you have much more control over the spawned process. By using thedwCreationFlags
parameter you can force the new process to get its own console (use theCREATE_NEW_CONSOLE
flag), but per default it will inherit the console of the parent process as well.