首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

一个关于InitInstance()返回值的有关问题

2012-03-12 
一个关于InitInstance()返回值的问题MSDN上说InitInstance()成功返回非0值,不成功返回0,那为什么我用类向

一个关于InitInstance()返回值的问题
MSDN上说InitInstance()成功返回非0值,不成功返回0,那为什么我用类向导默认生成的最后一行都是return FALSE,
而且它运行也没有问题啊???还有就是手动改成TRUE运行也没有区别啊??
BOOL CChatApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls();// Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();// Call this when linking to MFC statically
#endif

CChatDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

[解决办法]
这个是dialog
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
 
换成MDI就会看到return TRUE了
[解决办法]
这是MFC的框架,你用F11单步运行就知道了,你会看到以下的代码:
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();

InitFailure:
如果return true,就会运行nReturnCode = pThread->Run();

热点排行