如何从命令行阻止 MFC 应用程序?

How can I get an MFC application to block from the command line?(如何从命令行阻止 MFC 应用程序?)

本文介绍了如何从命令行阻止 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 之前退出,我通过从 CDocument 特化调用 exit(0) 来执行.

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.

我的问题是,对于我们的工作流程,将从 Windows 命令行调用 MFC 应用程序.一旦它被调用,它就会将控制权返回给 shell,并在后台愉快地继续前进,无论它是否打开了 GUI.我需要应用程序做的是从命令行阻止,无论 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 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何从命令行阻止 MFC 应用程序?

基础教程推荐