架構、文檔、視圖類之間的調用關係

來源:互聯網
上載者:User
1、主架構(CFrameWnd)中訪問視圖(CView)
  CView* GetActiveView() const;
  通常定義的視圖為CView的衍生類別,在調用自訂視圖對象的方法時

應該這樣寫:((CMouseKeyView*)GetActiveView())->MyFunc();

2、主架構(CFrameWnd)中訪問文檔(CDocument)
  GetActiveDocument,返回CDocument對象;

3、在視圖(CView)中訪問文檔(CDocument)
  inline CMouseKeyDoc* CMouseKeyView::GetDocument()
    {return (CMouseKeyDoc*)m_pDocument;}

4、在視圖(CView)中訪問架構(CFrameWnd)
  CFrameWnd* GetParentFrame() const;

5、在文檔(CDocument)中訪問架構(CFrameWnd)
  CWnd* AfxGetMainWnd();
  CWnd* AfxGetApp()->m_pMainWnd;

6、在文檔(CDocument)中訪問視圖(CView)
  UpdateAllViews
  功能:通知所有的視圖文檔已被修改的資訊
  原型:
    void UpdateAllViews(
      CView* pSender,  // 要更新的視圖指標,如果希望更新所有視

圖,將此參數設為NULL
      LPARAM lHint=0L, // 包含更改訊息的通知
      CObject* pHint=NULL // 保管更改訊息的對象
    }

7、在其他類中訪問文檔類(CDocument)
  CDocument* GetDocument()
  {
    CFrameWnd* frm=(CFrameWnd*)::AfxGetMainWnd();
    ASSERT(frm);
    CDocument* pDoc=frm->GetActiveDocument();
    ASSERT(pDoc);
    ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CMouseKeyDoc)));
    return (CMouseKeyDoc*)pDoc;
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.