mfc的程序调用CWinApp全局对象的循环,岂不是不会进入winmain了?
我用VC创建一个控制台程序,支持MFC,代码如下:
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
}
else
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
return nRetCode;
}
问题: 就像MFC的应用程序一样,CWinApp类型的全局对象,是在main函数入口之前被创建的。这个对象创建了之后就进入其消息循环了。在没有消息的时候会阻塞等待。这样的话岂不是就没有机会进入winmain了吗?
我的理解哪里有问题呢?
谢谢。
[解决办法]
代码中不是注释到了么
nReturnCode = pThread->Run();//这里才进入消息循环