MFC类层次结构及程序模拟(1)

1.MFC类层次结构

在这里插入图片描述

2.模拟程序

头文件MFC.H

#include <iostream>
using namespace std;

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

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

};

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

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

class CWnd:public CCmdTarget
{
    public:
		CWnd::CWnd(){cout<<"CWnd Constructor"<<endl;}
		CWnd::~CWnd(){cout<<"CWnd Destructor"<<endl;}
};
class CFrameWnd:public CWnd
{
    public:
		CFrameWnd::CFrameWnd(){cout<<"CFrameWnd Constructor"<<endl;}
		CFrameWnd::~CFrameWnd(){cout<<"CFrameWnd Destructor"<<endl;}
};
class CView:public CWnd
{
    public:
		CView::CView(){cout<<"CView Constructor"<<endl;}
		CView::~CView(){cout<<"CView Destructor"<<endl;}
};
CWinApp* AfxGetApp();

MFC.cpp

#include "StdAfx.h"
#include "my.h"
extern CMyWinApp theApp;
CWinApp* AfxGetApp()
{
	return theApp.m_pCurrentWinApp;
}

my.h

#include<iostream>
#include"MFC.h"
class CMyWinApp:public CWinApp
{
	public:
		CMyWinApp::CMyWinApp(){cout<<"CMyWinApp Constructor"<<endl;}
		CMyWinApp::~CMyWinApp(){cout<<"CMyWinApp Destructor"<<endl;}
};

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

main 函数

#include "stdafx.h"
#include "my.h"
#include"stdlib.h"

CMyWinApp theApp;//global object
int _tmain(int argc, _TCHAR* argv[])
{
	CWinApp* pApp=AfxGetApp();
	system("pause");
	
	return 0;
}

结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值