virtual BOOL InitApplication() { cout << "CWinApp::InitApplication /n"; return TRUE; }
virtual BOOL InitInstance() { cout << "CWinApp::InitInstance /n"; return TRUE; }
virtual int Run() { cout << "CWinApp::Run /n"; return CWinThread::Run();}
};
class CDocument : public CCmdTarget
{
public:
CDocument::CDocument() { }
CDocument::~CDocument() { }
};
class CWnd : public CCmdTarget
{
public:
CWnd::CWnd() { }
CWnd::~CWnd() { }
virtual BOOL Create();
BOOL CreateEx();
virtual BOOL PreCreateWindow();
};
class CFrameWnd : public CWnd
{
public:
CFrameWnd::CFrameWnd() { }
CFrameWnd::~CFrameWnd() { }
BOOL Create();
virtual BOOL PreCreateWindow();
};
class CView : public CWnd
{
public:
CView::CView() { }
CView::~CView() { }
};
// global function
CWinApp* AfxGetApp();
//------------------------------------------------------
// MY.H
//------------------------------------------------------
#include <iostream>
#include "mfc.h"
class CMyWinApp : public CWinApp
{
public:
CMyWinApp::CMyWinApp() { }
CMyWinApp::~CMyWinApp() { }
virtual BOOL InitInstance();
};
class CMyFrameWnd : public CFrameWnd
{
public:
CMyFrameWnd();
~CMyFrameWnd() { }
};
//---------------------------------------------------------------
// MFC.CPP
//---------------------------------------------------------------
#include "my.h" // 原该包含mfc.h 就好,但为了CMyWinApp 的定义,所以...
extern CMyWinApp theApp; // external global object
BOOL CWnd::Create()
{
cout << "CWnd::Create /n";
return TRUE;
}
BOOL CWnd::CreateEx()
{
cout << "CWnd::CreateEx /n";
PreCreateWindow();
return TRUE;
}
BOOL CWnd::PreCreateWindow()
{
cout << "CWnd::PreCreateWindow /n";
return TRUE;
}
BOOL CFrameWnd::Create()
{
cout << "CFrameWnd::Create /n";
CreateEx();
return TRUE;
}
BOOL CFrameWnd::PreCreateWindow()
{
cout << "CFrameWnd::PreCreateWindow /n";
return TRUE;
}
CWinApp* AfxGetApp()
{
return theApp.m_pCurrentWinApp;
}
//---------------------------------------------------------------
// MY.CPP
//---------------------------------------------------------------
#include "my.h"
CMyWinApp theApp; // global object
BOOL CMyWinApp::InitInstance()
{
cout << "CMyWinApp::InitInstance /n";
m_pMainWnd = new CMyFrameWnd;
return TRUE;
}
CMyFrameWnd::CMyFrameWnd()
{
cout << "CMyFrameWnd::CMyFrameWnd /n";
Create();
}
//---------------------------------------------------------------
// main
//---------------------------------------------------------------
void main()
{
CWinApp* pApp = AfxGetApp();
pApp->InitApplication();
pApp->InitInstance();
pApp->Run();
}
CWinApp::InitApplication
CMyWinApp::InitInstance
CMyFrameWnd::CMyFrameWnd
CFrameWnd::Create
CWnd::CreateEx
CFrameWnd::PreCreateWindow
CWinApp::Run
CWinThread::Run
请按任意键继续. . .