我想知道框架内部的initInstance()是何时调用的。我认为框架内部的WINMAIN类似:int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
if(!pGlobalGAFWinApp)
{
MessageBox("错误警告:找不到框架程序类实例,游戏程序初始化失败!\n""请检查程序是否设定了CGAFApp类的实例对象。",
“错误”, MB_OK|MB_ICONSTOP);
return -1;
} pGlobalGAFWinApp->m_hInstance = hInstance;//pGlobalGAFWinApp类似内部指向实例的指针 if(pGlobalGAFWinApp->InitInstance())//我们自己重载的初始化函数
{
pGlobalGAFWinApp->Run();
return pGlobalGAFWinApp->ExitInstance();
}
else return -1;
}
我想问一下,框架内部本身有InitInstance函数。这函数实现的是注册窗口类和建立窗口的任务。但是如果我们重载的InitInstance如下:BOOL CMyApp::InitInstance()
{ m_pMainWnd=new cMyFrame();
m_pMainWnd->showWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}他并没有注册窗口类和创建窗口的功能。
难道他会同时调用内部的InitInstance吗?但根据C++语法这里不可能的。请高手解我迷惑~~~~~~
LPSTR lpCmdLine, int nCmdShow)
{
if(!pGlobalGAFWinApp)
{
MessageBox("错误警告:找不到框架程序类实例,游戏程序初始化失败!\n""请检查程序是否设定了CGAFApp类的实例对象。",
“错误”, MB_OK|MB_ICONSTOP);
return -1;
} pGlobalGAFWinApp->m_hInstance = hInstance;//pGlobalGAFWinApp类似内部指向实例的指针 if(pGlobalGAFWinApp->InitInstance())//我们自己重载的初始化函数
{
pGlobalGAFWinApp->Run();
return pGlobalGAFWinApp->ExitInstance();
}
else return -1;
}
我想问一下,框架内部本身有InitInstance函数。这函数实现的是注册窗口类和建立窗口的任务。但是如果我们重载的InitInstance如下:BOOL CMyApp::InitInstance()
{ m_pMainWnd=new cMyFrame();
m_pMainWnd->showWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}他并没有注册窗口类和创建窗口的功能。
难道他会同时调用内部的InitInstance吗?但根据C++语法这里不可能的。请高手解我迷惑~~~~~~
解决方案 »
- MFC中EDIT框的输出问题
- 关于属性表对话框
- 属性页自定义按钮添加问题
- mfc 对话框程序如何实现文档视图中滚动条的拖动效果 ? 谢谢
- 有关函数参数为action的问题
- 求助:如何在C++里将一个10进制的浮点数转换成十六进制的数形式输出?
- 用SQLConfigDataSource 注册SQL SERVER数据库的 DSN的问题。。。。。。。。。。。
- 如何恢复?
- mscom能不能实现多机通讯
- 有做嵌入式或者对其赶兴趣的朋友,请进。
- 关于按钮的颜色
- 我想请问象WINDOWS的开始菜单一样,在MENU的左边有竖条的样式,那是如何实现的。有的说是用MF_MENUBREAK的flag,是在WM_DRAWITEM中处理的
cMyFrame类中创建窗口的呢?????唉,我头都大了,高手快进来啊~~~~~
BOOL CMyApp::InitInstance()
{ m_pMainWnd=new cMyFrame();
m_pMainWnd.Create(……);//此处要创建窗口
m_pMainWnd->showWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}你可以按F11启动程序,然后一步一步的跟踪,就可以看清楚调用的流程了
下面是WINMAIN.cpp中的片断/////////////////////////////////////////////////////////////////////////////
// Standard WinMain implementation
// Can be replaced as long as 'AfxWinInit' is called firstint AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL); int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp(); // AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure; // App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure; // Perform specific initializations
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:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif AfxWinTerm();
return nReturnCode;
}
AfxWinMain在winmain.cpp里
AfxRegisterWndClass
AfxRegisterClass
在afxwin.h里
MFC同样是用这些东西注册和创建窗口的。
(我的是VC7)