Run MFC app as a console app

Flaviu_ 911 Reputation points

I have a SDI MFC app. CView based on CRichEditView, where I print some messages. Nothing fancy. Is there possible to run this SDI MDC app as console app, without GUI, but dispatching messages to console instead of CRichEditView?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes

Accepted answer
  1. RLWA32 40,021 Reputation points

    Here is another way to "convert" an MFC SDI application into a console application.

    Code for InitInstance -

    	if (m_lpCmdLine && *m_lpCmdLine)
    		puts("This is the console interface");
    		puts("The MFC main window has not been created");
    		puts("Hit a key to exit the program");
    		return FALSE;  // exit the program
    		ShowWindow(GetConsoleWindow(), SW_HIDE);

    Code for ExitInstance to restore console if hidden -

    int CMFCSDIconsoleApp::ExitInstance()
    	//TODO: handle additional resources you may have added
    	ShowWindow(GetConsoleWindow(), SW_SHOW);

    After building the MFC SDI app use the VC++ EDITBIN utility to change the subsystem --


1 additional answer

Sort by: Most helpful
  1. RLWA32 40,021 Reputation points