简体   繁体   中英

MFC console mode application

I created an MFC application from visual studio 2008 MFC Application template. 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).

Can anyone please tell me how could ! display a console instead of window in an MFC application?

When you create a new Win32 Console application, the wizard has a checkbox to add common header files for MFC - check it.

This isn't very commonly done because there isn't much of MFC that's useful in a console application. You won't be running MFC's application message pump so a lot of things just won't work.

You can change the project's subsystem to console, when the MFC application windows running and also a console running.

If you want only a console running, create a console project instead.

Change project settings from Linker > System > SubSystem to "CONSOLE" instead of "WINDOWS".

Also if you want to attach console in your windows application then use "Editbin" utility from Visual Studio Tools. It is located in \\VC\\bin\\editbin.exe

editbin.exe /SUBSYSTEM:CONSOLE YourApplicationPath.exe

This will attach console in you windows application.

In your stdafx.h (before vs2019) or pch.h (vs2019) :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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