下面是我根据书上讲的MFC启动流程添加的启动标记:第4步:
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
//***********************************************
AfxMessageBox("NO.4: CMainFrame::CMainFrame().");
//***********************************************
}第5步:
BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
//***********************************************
AfxMessageBox("NO.5: CMainFrame::Create(...).");
//***********************************************
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}第6步:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
//*******************************************************
AfxMessageBox("NO.6: CMainFrame::PreCreateWindow(...).");
//*******************************************************
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return TRUE;
}问题出来了:程序执行完第4步,并没有执行第5步,而是直接进入了第6步,而且第6步连着执行了两次。请问问题出在哪里?请继续看后面---------
第12步:
int CHelloView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
//*******************************************************
AfxMessageBox("NO.12: CHelloView::OnCreate(...).");
//*******************************************************
return 0;
}第13步:
BOOL CHelloDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE; // TODO: add reinitialization code here
// (SDI documents will reuse this document)
//*******************************************************
AfxMessageBox("NO.13: CHelloDoc::OnNewDocument().");
//*******************************************************
return TRUE;
}第14步:
void CHelloDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
//*******************************************************
AfxMessageBox("NO.14: CHelloDoc::DeleteContents().");
//*******************************************************
CDocument::DeleteContents();
}第15步:
void CHelloView::OnInitialUpdate()
{
CView::OnInitialUpdate();
//*******************************************************
AfxMessageBox("NO.15: CHelloView::OnInitialUpdate().");
//*******************************************************
// TODO: Add your specialized code here and/or call the base class
}
又有问题了:程序执行完第12步,并没有进入第13步,而是直接进入了第14步,执行完第14步后才进入第13步,然后进入了第15步。请问问题出在哪里?
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
//***********************************************
AfxMessageBox("NO.4: CMainFrame::CMainFrame().");
//***********************************************
}第5步:
BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
//***********************************************
AfxMessageBox("NO.5: CMainFrame::Create(...).");
//***********************************************
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}第6步:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
//*******************************************************
AfxMessageBox("NO.6: CMainFrame::PreCreateWindow(...).");
//*******************************************************
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return TRUE;
}问题出来了:程序执行完第4步,并没有执行第5步,而是直接进入了第6步,而且第6步连着执行了两次。请问问题出在哪里?请继续看后面---------
第12步:
int CHelloView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
//*******************************************************
AfxMessageBox("NO.12: CHelloView::OnCreate(...).");
//*******************************************************
return 0;
}第13步:
BOOL CHelloDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE; // TODO: add reinitialization code here
// (SDI documents will reuse this document)
//*******************************************************
AfxMessageBox("NO.13: CHelloDoc::OnNewDocument().");
//*******************************************************
return TRUE;
}第14步:
void CHelloDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
//*******************************************************
AfxMessageBox("NO.14: CHelloDoc::DeleteContents().");
//*******************************************************
CDocument::DeleteContents();
}第15步:
void CHelloView::OnInitialUpdate()
{
CView::OnInitialUpdate();
//*******************************************************
AfxMessageBox("NO.15: CHelloView::OnInitialUpdate().");
//*******************************************************
// TODO: Add your specialized code here and/or call the base class
}
又有问题了:程序执行完第12步,并没有进入第13步,而是直接进入了第14步,执行完第14步后才进入第13步,然后进入了第15步。请问问题出在哪里?
看深入浅出MFC吧