Relationship between frameworks and message transmission rules in the MFC Document view

Source: Internet
Author: User

In MFC, the document-view structure concept is introduced. A document is equivalent to a data container, and a window that views data or interacts with data.Therefore, a complete application is generally composed of four classes: cwinapp application class, cframewnd window framework class, cdocument class, And cview class.

InProgramDuring running, the cwinapp will create a cframewnd Framework Window instance.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 needAnd operations depending on the framework. The various actions of the framework have been arranged by MFC without human intervention. This is also the M $ design document-According to the structure, let us focus on the completion of the task and release it from the interface writing.

In applicationOne view corresponds to one document,A document can contain multiple views.Only one frame window is used in an application.For the multi-document interface, there may be multiple MDI subwindow. Each video is a subwindow.The parent window is the frame window. In the multi-document interface, the parent window is an MDI child window. A multi-document application can contain multiple document templates,One TemplateDefinedOne documentAndOne or moreRelationship between views. The same document can belong to multiple templates,Only one document can be defined in a template.. The same view can also belong to multiple document templates. 

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

 

● The global function afxgetapp can obtain the cwinapp application class pointer.
● Afxgetapp ()-> m_pmainwnd is the frame window pointer
● In the Framework Window: cframewnd: getactivedocument to get the pointer to the current activity document
● In the frame window: cframewnd: getactiveview to get the current active video pointer
● In view: cview: getdocument, get the corresponding document pointer.
● In the document: cdocument: getfirstviewposition, cdocument: getnextview is used to traverse all associated views of the document.
● In the document: cdocument: getdoctemplate, get the document template pointer.
● In 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, message ing is defined inIf 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.

The document is used to save data, and the view is used for interaction. Both the document and view are generated by the framework.

 

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.