1

I'd like to create a tool that can either act as command line (display some console output based on input parameters), or display a window, based on input parameters.

I'm using MSV2012 with C++, and it seems you have to 'choose' between console and window app.

I know the net is filled with samples which use AllocConsole() and redirect std::out, but it doesn't make it feel like a command line application : calling the exe from the windows console will open a new window with the console output...

Is there a way to have it use the current console window instead of allocating a new one?

If not possible, I'll make 2 applications instead, but that's a pity..

4

2 回答 2

1

其他人可能有更权威的答案,但我不相信它得到支持。

通常的解决方法是创建一个 Windows 应用程序,但有一个从 CLI 启动它的命令行包装器(并提供与原始控制台通信的通道)。

于 2012-12-16T09:28:12.200 回答
0

它在技术上不受支持,但我通过获取当前进程的快照找到了一个很好的解决方案,找到父进程,如果它是一个控制台应用程序,则附加到它的控制台或使用 AllocConsole 创建一个,重定向输出,获取父进程的线程如果它是 cmd.exe 并暂停它,在我退出我的应用程序之前恢复它

于 2018-05-11T19:41:25.670 回答