English 中文(简体)
MFC - Document View
  • 时间:2024-12-22

MFC - Document View


Previous Page Next Page  

The Document/View architecture is the foundation used to create apppcations based on the Microsoft Foundation Classes pbrary. It allows you to make distinct the different parts that compose a computer program including what the user sees as part of your apppcation and the document a user would work on. This is done through a combination of separate classes that work as an ensemble.

The parts that compose the Document/View architecture are a frame, one or more documents, and the view. Put together, these entities make up a usable apppcation.

View

A view is the platform the user is working on to do his or her job. To let the user do anything on an apppcation, you must provide a view, which is an object based on the CView class. You can either directly use one of the classes derivedfrom CView or you can derive your own custom class from CView or one of its child classes.

Document

A document is similar to a bucket. For a computer apppcation, a document holds the user s data. To create the document part of this architecture, you must derive an object from the CDocument class.

Frame

As the name suggests, a frame is a combination of the building blocks, the structure, and the borders of an item. A frame gives "physical" presence to a window. It also defines the location of an object with regards to the Windows desktop.

Single Document Interface (SDI)

The expression Single Document Interface or SDI refers to a document that can present only one view to the user. This means that the apppcation cannot display more than one document at a time. If you want to view another type of document of the current apppcation, you must create another instance of the apppcation. Notepad and WordPad are examples of SDI apppcations.

Let us look into a simple example of single document interface or SDI by creating a new MFC dialog based apppcation.

Step 1 − Let us create a new MFC Apppcation MFCSDIDemo with below mentioned settings.

SDI

Step 2 − Select Single document from the Apppcation type and MFC standard from Project Style.

Step 3 − Cpck Finish to Continue.

Step 4 − Once the project is created, run the apppcation and you will see the following output.

SDI

Multiple Document Interface (MDI)

An apppcation is referred to as a Multiple Document Interface, or MDI, if the user can open more than one document in the apppcation without closing it. To provide this functionapty, the apppcation provides a parent frame that acts as the main frame of the computer program. Inside this frame, the apppcation allows creating views with inspanidual frames, making each view distinct from the other.

Let us look into a simple example of multiple document interface or MDI by creating a new MFC dialog based apppcation.

Step 1 − Let us create a new MFC Apppcation MFCMDIDemo with below mentioned settings.

MDI

Step 2 − Select Multiple document from the Apppcation type and MFC standard from Project Style.

Step 3 − Cpck Finish to Continue.

Step 4 − Once the project is created, run the apppcation and you will see the following output.

MDI

Step 5 − When you cpck on File → New menu option, it will create another child window as shown in the following snapshot.

MDI

Step 6 − In Multiple Document Interface (MDI) apppcations, there is one main frame per apppcation. In this case, a CMDIFrameWnd, and one CMDIChildWnd derived child frame for each document.

Advertisements