如何获得一个MFC应用程序从命令行阻止? [英] How can I get an MFC application to block from the command line?

查看:143
本文介绍了如何获得一个MFC应用程序从命令行阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为OpenCascade修改了一个MFC示例,添加了一些功能(它是HLR示例)。应用程序使用文档/视图体系结构,文档类执行大部分工作。

I modified an MFC example for OpenCascade, adding some functionality (it was the HLR example). The application uses the document/view architecture, with document class doing most of the work.

一些新功能不需要GUI,因此程序退出之前我打开了GUI,我通过调用 exit(0)从CDocument专业化。

Some of the new functions don't require a GUI, so the program exits before the GUI is opened, which I perform by calling exit(0) from a CDocument specialization.

我的问题是,对于我们的工作流,MFC应用程序将从Windows命令行调用。一旦它被调用,它返回控制回到shell,并继续在后台,无论是否打开一个GUI。

My problem is, for our workflow, the MFC application will be called from the Windows command line. As soon as it's called, it returns control back to the shell and continues merrily along in the background, whether it opens a GUI or not. What I need the application to do is to block from the command line, whether the GUI is open or not.

我一直在阅读CWinApp和CMDIFrameWnd,我想知道,但如果你可以从命令行中创建你的应用程序块,我不知道该怎么做。

I've been reading up on CWinApp, and CMDIFrameWnd, but if you can make your application block from the command line, I can't figure out how to do it.

推荐答案

您将可执行文件设置为具有链接器选项/ SUBSYSTEM:CONSOLE的控制台应用程序,命令行将阻止,直到应用程序退出。记住,控制台应用程序可以有一个Windows GUI。

If you set your executable to be a console application with the linker option /SUBSYSTEM:CONSOLE the command line will block till the application exits. Remember that A console application can have a windows GUI.

设置链接器设置/ SUBSYSTEM:CONSOLE确实有一个问题,如果你这样做作为链接器设置,你将必须调整入口点为main(),而不是winmain 。在下面的线程中有几个解决方法(感谢Ulrich Eckhardt提到的入口点):
Visual Studio 2012 C ++标准输出

Setting the linker setting /SUBSYSTEM:CONSOLE does have one problem if you do that as a linker setting you will have to adjust entry point to be main() instead of winmain. In the following thread there are a few a workarounds for that (thanks for Ulrich Eckhardt mentioning the entry point) : Visual Studio 2012 C++ Standard Output

此方法还有一个第二个负面。如果程序不是从控制台窗口运行,应用程序将为您创建一个控制台窗口。这可能会混淆用户。

There is also a second negative of this approach. If the program is not run from a console window the application will create a console window for you. This may confuse users.

这篇关于如何获得一个MFC应用程序从命令行阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆