• App Doc View Frame中指针的获取


    // App中获取其它三项指针
    void CSDIApp::OnApp()
    {
        // App
        // Doc
        CDocument *pDoc = ((CFrameWndEx *)m_pMainWnd)->GetActiveDocument();//成员变量CFrameWndEx m_pMainWnd
        // MainFrame
        CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
        // View
        CView *pView = ((CFrameWndEx *)m_pMainWnd)->GetActiveView();
    }
    // Doc中获取其它三项指针
    CSDIDoc::CSDIDoc()//构造函数
    {
        // App
        CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
        // Doc
        // MainFrame
        // Doc的创建先于MainFrame
        // View
        // Doc的创建先于View
    }
    void CSDIDoc::OnDoc()
    {
        // App
        // 同构造函数
        // Doc
        // MainFrame
        CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
        // View
        CView *pView= (CView *)pMain->GetActiveView();    
        POSITION pos = GetFirstViewPosition();      
        pView = GetNextView(pos);
    }
    // MainFrame中获取其它三项指针
    CMainFrame::CMainFrame()//构造函数
    {
        theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2005);
        // App
        CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
        // Doc
        // 构造函数里无法得到当前激活的Doc
        // MainFrame
        // View
        // 构造函数里无法得到View指针,因为Main先于View创建。
    }
    void CMainFrame::OnMain()
    {
        // App
        // 同构造函数
        // Doc
        CDocument *pDoc = (CDocument *)GetActiveDocument();
        // MainFrame
        // View
        CView *pView = (CView *)GetActiveView();
    }
    // View中获取其它三项指针
    CSDIView::CSDIView()//构造函数
    {
        // App
        CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
        // Doc
        /* 无法在View的构造函数里得到Doc指针
           GetDocument();实际上是返回m_pDocument
           m_pDocument在OnCreate();里创建        */
        //CDocument *pDoc = GetDocument();
        // MainFrame
        // 构造函数里无法得到MainFrame指针
        // CFrameWndEx *pMain = (CFrameWndEx *)pApp->m_pMainWnd;
        // View
    }
    void CSDIView::OnView()
    {
        // App
        // 同构造函数
        // Doc
        CDocument *pDoc = GetDocument();
        // MainFrame
        CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
        // View
    }
    // Dlg中获取指针
    CDlg::CDlg(CWnd* pParent /*=NULL*/)//构造函数
        : CDialog(CDlg::IDD, pParent)
    {
        // App
        CWinAppEx *pApp = (CWinAppEx *)AfxGetApp();
        // Doc
        CDocument *pDoc = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveDocument();
        // MainFrame
        CFrameWndEx *pMain = (CFrameWndEx *)AfxGetMainWnd();
        // View
        CView *pView = ((CFrameWndEx *)AfxGetMainWnd())->GetActiveView();
    }
    
  • 相关阅读:
    Solution -「CF 1025G」Company Acquisitions
    Solution -「Code+#4」「洛谷 P4370」组合数问题 2
    YApi,顶尖API接口管理平台
    Hibernate (开放源代码的对象关系映射框架)
    【LeetCode】5. 最长回文子串
    【LeetCode】105. 从前序与中序遍历序列构造二叉树
    【LeetCode】76. 最小覆盖子串
    【LeetCode】974. 和可被 K 整除的子数组
    【LeetCode】394. 字符串解码
    【LeetCode】5424. 数组中两元素的最大乘积
  • 原文地址:https://www.cnblogs.com/sgdd123/p/7868286.html
Copyright © 2020-2023  润新知