• MFC程序初始化过程


    //MFC.h
    #define	BOOL	int
    #define	TRUE	1
    #define FALSE	0
    
    
    #include <iostream>
    using namespace std;
    
    
    class CObject
    {
    public:
    	CObject(){};
    	~CObject(){};
    };
    
    class CCmdTarget : public CObject
    {
    public:
    	CCmdTarget(){};
    	~CCmdTarget(){};
    };
    
    class CWinThread : public CCmdTarget
    {
    public:
    	CWinThread(){};
    	~CWinThread(){};
    
    	virtual BOOL InitInstance()
    	{
    		cout<<"CWinThread::InitInstance"<<endl;
    		return TRUE;
    	}
    	virtual int Run()
    	{
    		cout<<"CWinThread::Run"<<endl;
    		return 1;
    	}
    };
    
    
    class CWnd;//声明
    
    class CWinApp : public CWinThread
    {
    public:
    	CWinApp *m_pCurrentWinApp;
    	CWnd *m_pMainWnd;
    
    public:
    	CWinApp()
    	{
    		m_pCurrentWinApp = this;
    	}
    	~CWinApp()
    	{
    	}
    
    	virtual BOOL InitApplication()
    	{
    		cout<<"CWinApp::InitApplication"<<endl;
    		return TRUE;
    	}
    
    	virtual BOOL InitInstance()
    	{
    		cout<<"CWinApp::InitInstance"<<endl;
    		return TRUE;
    	}
    
    	virtual int Run()
    	{
    		cout<<"CWinApp::Run"<<endl;
    		return CWinThread::Run();
    	}
    };
    
    
    class CDocument : public CCmdTarget
    {
    public:
    	CDocumnt(){};
    	~CDocument(){};
    };
    
    class CWnd : public CCmdTarget
    {
    public:
    	CWnd(){};
    	~CWnd(){};
    
    public:
    	virtual BOOL Create();
    	BOOL CreateEx();
    	virtual BOOL PreCreateWindow();
    };
    
    class CFrameWnd : public CWnd
    {
    public:
    	CFrameWnd(){};
    	~CFrameWnd(){};
    
    public:
    	virtual BOOL Create();
    	virtual BOOL PreCreateWindow();
    };
    
    class CView : public CWnd
    {
    public:
    	CView(){};
    	~CView(){};
    };
    
    //global function
    CWinApp* AfxGetApp();
    
    
    
    //MY.h
    #include "MFC.h"
    #include <iostream>
    using namespace std;
    
    class CMyWinApp : public CWinApp
    {
    public:
    	CMyWinApp(){};
    	~CMyWinApp(){};
    
    public:
    	virtual BOOL InitInstance();
    };
    
    
    class CMyFrameWnd : public CFrameWnd
    {
    public:
    	CMyFrameWnd();
    	~CMyFrameWnd(){};
    };
    
    
    //MFC.cpp
    #include "MY.h"
    
    extern CMyWinApp theApp;//extern global object
    
    BOOL CWnd::Create()
    {
    	cout<<"CWnd::Create"<<endl;
    	return TRUE;
    }
    
    
    BOOL CWnd::CreateEx()
    {
    	cout<<"CWnd::CreateEx"<<endl;
    	PreCreateWindow();
    	return TRUE;
    }
    
    
    BOOL CWnd::PreCreateWindow()
    {
    	cout<<"CWnd::PreCreateWindow"<<endl;
    	return TRUE;
    }
    
    BOOL CFrameWnd::Create()
    {
    	cout<<"CFrameWnd::Create"<<endl;
    	CreateEx();
    	return TRUE;
    }
    
    
    BOOL CFrameWnd::PreCreateWindow()
    {
    	cout<<"CFrameWnd::PreCreateWnd"<<endl;
    	return TRUE;
    }
    
    
    CWinApp* AfxGetApp()
    {
    	return theApp.m_pCurrentWinApp;
    }
    
    
    
    //MY.cpp
    #include "MY.h"
    
    CMyWinApp theApp;//global object
    
    BOOL CMyWinApp::InitInstance()
    {
    	cout<<"CMyWinApp::InitInstance"<<endl;
    	this->m_pMainWnd = new CMyFrameWnd;
    	return TRUE;
    }
    
    
    CMyFrameWnd::CMyFrameWnd()
    {
    	cout<<"CMyFrameWnd::CMyFrameWnd"<<endl;
    	Create();
    }
    
    
    void main()
    {
    	CWinApp* pApp = AfxGetApp();
    
    	pApp->InitApplication();
    	pApp->InitInstance();
    	pApp->Run();
    }
    
  • 相关阅读:
    &与&&的区别
    x^y=(x&~y)|(~x&y)证明
    a、b交换与比较
    x+y = ((x&y)<<1) + (x^y) 证明
    (x&y) + ((x^y)>>1)即x和y的算数平均值
    默认参数提升
    类型转换
    闲扯原码,补码和反码(转)
    C/C++中float和double的存储结构
    led设备驱动(s3c_led.c)
  • 原文地址:https://www.cnblogs.com/steady/p/1924939.html
Copyright © 2020-2023  润新知