Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 825
Muhammad Fahad Ahmed Avatar asked Feb 19 '23 02:02

Muhammad Fahad Ahmed


2 Answers

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.

like image 183
Mark Ransom Avatar answered Feb 28 '23 01:02

Mark Ransom


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
like image 24
sailfish009 Avatar answered Feb 28 '23 00:02

sailfish009