开发者

Using Delphi's ShellExecute() with the process inheriting the original console?

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 c开发者_如何学Goreate 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.


Using ShellExecute() you won't be able to make the spawned application use the same console. The HWND element in the ShellExecute() call is documented:

Specifies a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.

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 the dwCreationFlags parameter you can force the new process to get its own console (use the CREATE_NEW_CONSOLE flag), but per default it will inherit the console of the parent process as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜