Relationships Among MFC Objects(MFC各对象间的关系)

来源:互联网 发布:11活动淘宝电子打几折 编辑:程序博客网 时间:2024/06/03 20:12
  • A document keeps a list of the views of that document and a pointer to the document template that created the document.

    (文档对象保存一系列该文档对应视图,同时保存一个一个创建该文档对象的文档模板的指针)

  • A view keeps a pointer to its document and is a child of its parent frame window.

    (视图对象保存一个其指向的文档对象的指针,视图是其父框架窗口的子窗口)

  • A document frame window keeps a pointer to its current active view.

    (文档的框架窗口保存一个指向当前视图的指针)

  • A document template keeps a list of its open documents.

    (文档模板保存一系列由该模板创建并打开的文档对象)

  • The application keeps a list of its document templates.

    (the app对象保存一系列创建的文档模板对象)

  • Windows keeps track of all open windows so it can send messages to them.

    (Windows系统可追踪所有打开的窗口,以便其能发送消息到这些窗口)

    These relationships are established during document/view creation.

    这种关系的建立发生在Document/View创建期间。在程序中相互获取对象的方法如下:

    From object

    How to access other objects

    Document

    Use GetFirstViewPosition and GetNextView to access the document's view list.

    Call GetDocTemplate to get the document template.

    View

    Call GetDocument to get the document.

    Call GetParentFrame to get the frame window.

    Document frame window

    Call GetActiveView to get the current view.

    Call GetActiveDocument to get the document attached to the current view.

    MDI frame window

    Call MDIGetActive to get the currently active CMDIChildWnd.


    Typically, a frame window has one view, but sometimes, as in splitter windows, the same frame window contains multiple views. The frame window keeps a pointer to the currently active view; the pointer is updated any time another view is activated.

     通常一个Frame窗口只拥有一个View,但有时,例如在分割串口中,同一个Frame窗口可以包含多个View,此时,Frame窗口只保存当前活动View的指针,当其他View转变为活动View时,该指针会实时更新。

NoteNote

A pointer to the main frame window is stored in the m_pMainWnd member variable of the application object. A call to OnFileNew in your override of the InitInstance member function of CWinApp sets m_pMainWnd for you. If you do not call OnFileNew, you must set the variable's value in InitInstance yourself. (SDI COM component (server) applications may not set the variable if /Embedding is on the command line.) Note that m_pMainWnd is now a member of class CWinThread rather than CWinApp.

注意:

一个程序的主Frame窗口的指针是存储在m_pMainWnd成员变量中的。在你重写的Initinstance方法中调用OnFileNew可以设置自己的m_pMainWnd。如果不调用,就需要自己在InitInstance中设置m_pMainWnd。

原创粉丝点击