简体   繁体   English

MFC控制台模式应用程序

[英]MFC console mode application

I created an MFC application from visual studio 2008 MFC Application template. 我从Visual Studio 2008 MFC应用程序模板创建了MFC应用程序。 The problem is that I want to show a console in execution and not the window created by default MFC Application template ( like the one shown when we choose Win32 Console Application template). 问题是我想显示一个正在执行的控制台,而不是默认的MFC Application模板创建的窗口(就像我们选择Win32 Console Application模板时显示的那样)。

Can anyone please tell me how could ! 谁能告诉我怎么可能! display a console instead of window in an MFC application? 在MFC应用程序中显示控制台而不是窗口?

When you create a new Win32 Console application, the wizard has a checkbox to add common header files for MFC - check it. 当您创建新的Win32 Console应用程序时,该向导具有一个复选框,可以为MFC添加通用头文件-选中它。

This isn't very commonly done because there isn't much of MFC that's useful in a console application. 这不是很常见,因为在控制台应用程序中没有太多有用的MFC。 You won't be running MFC's application message pump so a lot of things just won't work. 您将不会运行MFC的应用程序消息泵,因此很多事情将无法正常工作。

You can change the project's subsystem to console, when the MFC application windows running and also a console running. 当MFC应用程序窗口正在运行且控制台也在运行时,您可以将项目的子系统更改为控制台。

If you want only a console running, create a console project instead. 如果只想运行控制台,请创建一个控制台项目。

Change project settings from Linker > System > SubSystem to "CONSOLE" instead of "WINDOWS". 将项目设置从“ 链接器”>“系统”>“子系统 ”更改为“ CONSOLE”,而不是“ WINDOWS”。

Also if you want to attach console in your windows application then use "Editbin" utility from Visual Studio Tools. 另外,如果要将控制台附加到Windows应用程序中,请使用Visual Studio Tools中的“ Editbin”实用程序。 It is located in \\VC\\bin\\editbin.exe 它位于\\ VC \\ bin \\ editbin.exe中

editbin.exe /SUBSYSTEM:CONSOLE YourApplicationPath.exe editbin.exe / SUBSYSTEM:CONSOLE YourApplicationPath.exe

This will attach console in you windows application. 这将在您的Windows应用程序中附加控制台。

In your stdafx.h (before vs2019) or pch.h (vs2019) : 在您的stdafx.h(vs2019之前)或pch.h(vs2019)中:

#ifdef _UNICODE
#pragma comment(linker, "/entry:wWinMainCRTStartup /subsystem:console") 
#else
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM