zoukankan      html  css  js  c++  java
  • 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();
    }
    
  • 相关阅读:
    优秀数
    加法检测器
    数字转换
    选课
    二叉苹果树
    分离与合体
    括号配对
    凸多边形的划分
    能量项链
    石子合并
  • 原文地址:https://www.cnblogs.com/steady/p/1924937.html
Copyright © 2011-2022 走看看