MFC类层次结构

//MFC.h
#include <iostream>
using namespace std;

class CObject
{
public:
	CObject()
	{
		cout<<"CObject Constructor"<<endl;
	}
	~CObject()
	{
		cout<<"CObject Destructor"<<endl;
	}
};

class CCmdTarget : public CObject
{
public:
	CCmdTarget()
	{
		cout<<"CCmdtarget Constructor"<<endl;
	}
	~CCmdTarget()
	{
		cout<<"CCmdTarget Destructor"<<endl;
	}
};

class CWinThread : public CCmdTarget
{
public:
	CWinThread()
	{
		cout<<"CWinThread Constructor"<<endl;
	}
	~CWinThread()
	{
		cout<<"CWinThread Destructor"<<endl;
	}
};

class CWinApp : public CWinThread
{
public:
	CWinApp *m_pCurrentWinApp;//**************

public:
	CWinApp()
	{
		m_pCurrentWinApp = this;
		cout<<"CWinApp Constructor"<<endl;
	}
	~CWinApp()
	{
		cout<<"CWinApp Destructor"<<endl;
	}
};


class CWnd : public CCmdTarget
{
public:
	CWnd()
	{
		cout<<"CWnd Constructor"<<endl;
	}
	~CWnd()
	{
		cout<<"CWnd Destructor"<<endl;
	}
};


class CView : public CWnd
{
public:
	CView()
	{
		cout<<"CView Constructor"<<endl;
	}
	~CView()
	{
		cout<<"CView Destructor"<<endl;
	}
};


class CFrameWnd : public CWnd
{
public:
	CFrameWnd()
	{
		cout<<"CFrameWnd Constructor"<<endl;
	}
	~CFrameWnd()
	{
		cout<<"CFrameWnd Destructor"<<endl;
	}
};


class CDocument : public CCmdTarget
{
public:
	CDocument()
	{
		cout<<"CDocument Constructor"<<endl;
	}
	~CDocument()
	{
		cout<<"CDocument Destructor"<<endl;
	}
};

//global function
CWinApp* AfxGetApp();



//MY.h
#include <iostream>
#include "MFC.h"
using namespace std;

class CMyWinApp : public CWinApp
{
public:
	CMyWinApp()
	{
		cout<<"CMyWinApp Constructor"<<endl;
	}
	~CMyWinApp()
	{
		cout<<"CMyWinApp Destructor"<<endl;
	}
};

class CMyFrameWnd : public CFrameWnd
{
public:
	CMyFrameWnd()
	{
		cout<<"CMyFrameWnd Constructor"<<endl;
	}
	~CMyFrameWnd()
	{
		cout<<"CMyFrameWnd Destructor"<<endl;
	}
};


//MFC.cpp
#include "MY.h"

extern CMyWinApp theApp;

CWinApp* AfxGetApp()
{
	return theApp.m_pCurrentWinApp;
}


//MY.cpp
#include "MY.h"

CMyWinApp theApp;//global object

void main()
{
	CWinApp* pApp = AfxGetApp();
}
posted @ 2011-01-03 20:10  Cranny  阅读(284)  评论(0编辑  收藏  举报