商务合作:179001057@qq.com

090919(星期六):MFC消息路由4, Frame8代码分析3CWinApp的聚合情况

技术2022-05-11  0


某平台价值19860元的编程课程资料免费领取【点我领取】


一、Frame8程序main函数第4-7

源码:

       CMyDoc* pMyDoc = new CMyDoc;

       CMyView* pMyView = new CMyView;

       CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; //此处的m_pMainWnd = new CMyFrameWnd

       pMyFrame->m_pViewActive = pMyView;

       pMyView->m_pDocument = pMyDoc;

 

 

       CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; //此处的m_pMainWnd

m_pMainWnd在什么地方产生的?

class CWinApp : public CWinThread

{

public:

       CWinApp* m_pCurrentWinApp;

       CWnd* m_pMainWnd;   //Applicaion是个大概念,包含一个CWnd

public:

       CWinApp::CWinApp() {

              m_pCurrentWinApp = this;

       }

pAppCMyWinApp类型,其m_pMainWnd变量是在CMyWinApp::InitInstance生成的。

BOOL CMyWinApp::InitInstance()

{

       cout << "CMyWinApp::InitInstance /n";

       m_pMainWnd = new CMyFrameWnd;

       return TRUE;

}

 

class CFrameWnd : public CWnd

{

public:

       CView* m_pViewActive; // current active view

public:

       CFrameWnd::CFrameWnd() {

       }

       CFrameWnd::~CFrameWnd() {

       }

      

 

class CView : public CWnd

{

public:

       CDocument* m_pDocument;

 

public:

       CView::CView() {

       }

       CView::~CView() {

       }

 

总之的意思是CWinApp聚合CFrameWndCFrameWnd聚合CViewCView聚合CDocument


最新回复(0)