Jump to content
  • Advertisement
Sign in to follow this  
kok1001

simple MFC problem

This topic is 3807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am a beginner , in Win32 console Application,i can have console window to REALTIME monitor the change of some data by "printf" of this data. but with MFC AppWizard(exe) ,i can't not do this (No console window for me to do it).... (VC6 ) can anyone help me? thx

Share this post


Link to post
Share on other sites
Advertisement
You should be able to set the subsystem to CONSOLE (under the project's linker settings), and then override MFC's WinMain. I came up with this by copying MFC's WinMain function and modifying it, and then stuck it in it's own main.cpp file. It seems to work...but be aware that this is probably the 3rd MFC I've ever compiled in my life and it could easily cause some kind of very weird problem that I'm not aware.


int main( int argc, char* argv[] )
{
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();

// AFX internal initialization
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL))
goto InitFailure;


// App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;

// Perform specific initializations
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();

InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif

AfxWinTerm();
return nReturnCode;
}





Also, be aware that you can simply redirect printf's to a file if you want.


std::freopen("stdout.txt", "w", stdout);
std::freopen("stderr.txt", "w", stderr);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!