Relationship between frameworks and message transmission rules in the document view

Source: Internet
Author: User

 

InIn MFC, M $ introduces the document-view structure concept. A document is equivalent to a data container, and a window that views data or interacts with data. (This structure is more extended during the development of OLE and ODBC in MFC.) Therefore, a complete application is generally composed of four classes: CWinApp application class and CFrameWnd window framework class, CDocument class, CView class. (VC6 supports creating apps without document-view)

When the program is runningCWinApp will create a CFrameWnd Framework Window instance, and the Framework Window will create a document template, and then a document template will create a document instance and a view instance, and associate the two. Generally, we only need to perform operations on documents and views. The various actions of the framework have been arranged by MFC without human intervention. This is also the intention of M $ design document-depending on the structure, let's focus on completing the task and release it from the interface writing.

A document corresponds to a document in an application, but a document can contain multiple views. Only one framework window is used in an application. For multi-document interfaces, multiple frameworks may exist.MDI child window. Each video is a child window. In the single document interface, the parent window is the framework window, and in the Multi-document interface, the parent window is the MDI child window. A multi-document application can contain multiple document templates. A template defines the correspondence between a document and one or more views. One document can belong to multiple templates, but only one document can be defined in one template. The same view can also belong to multiple document templates. (I do not know if it is clear)

Next let's take a look at how to get pointers to various objects in the program:

  • Global FunctionsAfxGetApp can get the CWinApp application class pointer
  • AfxGetApp ()-> m_pMainWnd is the frame window pointer
  • In the frame window:CFrameWnd: GetActiveDocument get the pointer to the current activity document
  • In the frame window:CFrameWnd: GetActiveView
  • In View:CView: GetDocument get the corresponding document pointer
  • In the document:CDocument: GetFirstViewPosition, CDocument: GetNextView is used to traverse all associated views.
  • In the document:CDocument: GetDocTemplate get document template pointer
  • On the multi-document interface:CMDIFrameWnd: MDIGetActive: Obtain the MDI subwindow of the current activity.

Generally, a user enters a message (such as a menu selection, mouse, or keyboard) to view the message first. If the view is not processed, the message is sent to the frame window. Therefore, you can define the message ing in the view. If an application has multiple views at the same time and the current activity does not process the message, the message will be sent to the Framework Window.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.