按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
成。稍后我会把注册动作挖出来,那将是窗口诞生前一刻的行为。
371
…………………………………………………………Page 434……………………………………………………………
第篇 湷觥 FC 程式設計
CWinApp::InitApplication
HELLO。CPP
1 CMyWinApp theApp; // application object
BOOL CMyWinApp::InitInstance()
WINMAIN。CPP
{
int AFXAPI AfxWinMain (。。。) m_pMainWnd = new CMyFrameWnd();
{ m_pMainWnd…》ShowWindow(m_nCmdShow);
CWinApp* pApp = AfxGetApp(); m_pMainWnd…》UpdateWindow();
return TRUE;
2 }
AfxWinInit(。。。);
3 pApp…》InitApplication(); CMyFrameWnd::CMyFrameWnd()
pApp…》InitInstance(); {
nReturnCode = pApp…》Run(); Create(NULL; 〃Hello MFC〃; 。。。;
〃MainMenu〃);
AfxWinTerm(); }
}
void CMyFrameWnd::OnPaint() { 。。。 }
void CMyFrameWnd::OnAbout() { 。。。 }
BEGIN_MESSAGE_MAP(CMyFrameWnd; CFrameWnd)
ON_MAND(IDM_ABOUT; OnAbout)
ON_WM_PAINT()
END_MESSAGE_MAP()
AfxWinInit 之后的动作是pApp …》InitApplication 。稍早我说过了,pApp 指向CMyWinApp
对象(也就是本例的theApp ),所以,当程序调用:
pApp…》InitApplication();
相当于调用:
CMyWinApp::InitApplication();
但是你要知道,CMyWinApp 继承自CWinApp,而InitApplication 又是CWinApp 的一个
虚拟函数;我们并没有改写它(大部份情况下不需改写它),所以上述动作相当于调用:
CWinApp::InitApplication();
此函数之源代码出现在APPCORE。CPP 中:
372
…………………………………………………………Page 435……………………………………………………………
第6章 MFC 程式的生死因果
BOOL CWinApp::InitApplication()
{
if (CDocManager::pStaticDocManager != NULL)
{
if (m_pDocManager == NULL)
m_pDocManager = CDocManager::pStaticDocManager;
CDocManager::pStaticDocManager = NULL;
}
if (m_pDocManager != NULL)
m_pDocManager…》AddDocTemplate(NULL);
else
CDocManager::bStaticInit = FALSE;
return TRUE;
}
这些动作都是MFC 为了内部管理而做的。
关于Document Template 和CDocManager ,第7章和第8章另有说明。
373
…………………………………………………………Page 436……………………………………………………………
第篇 湷觥 FC 程式設計
CMyWinApp::InitInstance
HELLO。CPP
1 CMyWinApp theApp; // application object
WINMAIN。CPP BOOL CMyWinApp::InitInstance()
{
int AFXAPI AfxWinMain (。。。) m_pMainWnd = new CMyFrameWnd();
{ m_pMainWnd…》ShowWindow(m_nCmdShow);
CWinApp* pApp = AfxGetApp(); m_pMainWnd…》UpdateWindow();
return TRUE;
2 }
AfxWinInit(。。。);
3 CMyFrameWnd::CMyFrameWnd()
pApp…》InitApplication();
pApp…》InitInstance(); {
4
nReturnCode = pApp…》Run(); Create(NULL; 〃Hello MFC〃; 。。。;
〃MainMenu〃);
AfxWinTerm(); }
}
void CMyFrameWnd::OnPaint() { 。。。 }
void CMyFrameWnd::OnAbout() { 。。。 }
BEGIN_MESSAGE_MAP(CMyFrameWnd; CFrameWnd)
ON_MAND(IDM_ABOUT; OnAbout)
ON_WM_PAINT()
END_MESSAGE_MAP()
继InitApplication 之后,AfxWinMain 调用pApp …》InitInstance 。稍早我说过了,pApp 指向
CMyWinApp 对象(也就是本例的theApp ),所以,当程序调用:
pApp…》InitInstance();
相当于调用
CMyWinApp::InitInstance();
但是你要知道,CMyWinApp 继承自CW