The Document/View architecture is the foundation used to create applications based on the Microsoft Foundation Classes library. It allows you to make distinct the different parts that compose a computer program including what the user sees as part of your application 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 application.
A view is the platform the user is working on to do his or her job. To let the user do anything on an application, 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.
A document is similar to a bucket. For a computer application, a document holds the user's data. To create the document part of this architecture, you must derive an object from the CDocument class.
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.
The expression Single Document Interface or SDI refers to a document that can present only one view to the user. This means that the application cannot display more than one document at a time. If you want to view another type of document of the current application, you must create another instance of the application. Notepad and WordPad are examples of SDI applications.
Let us look into a simple example of single document interface or SDI by creating a new MFC dialog based application.
Step 1 − Let us create a new MFC Application MFCSDIDemo with below mentioned settings.
Step 2 − Select Single document from the Application type and MFC standard from Project Style.
Step 3 − Click Finish to Continue.
Step 4 − Once the project is created, run the application and you will see the following output.
An application is referred to as a Multiple Document Interface, or MDI, if the user can open more than one document in the application without closing it. To provide this functionality, the application provides a parent frame that acts as the main frame of the computer program. Inside this frame, the application allows creating views with individual 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 application.
Step 1 − Let us create a new MFC Application MFCMDIDemo with below mentioned settings.
Step 2 − Select Multiple document from the Application type and MFC standard from Project Style.
Step 3 − Click Finish to Continue.
Step 4 − Once the project is created, run the application and you will see the following output.
Step 5 − When you click on File → New menu option, it will create another child window as shown in the following snapshot.
Step 6 − In Multiple Document Interface (MDI) applications, there is one main frame per application. In this case, a CMDIFrameWnd, and one CMDIChildWnd derived child frame for each document.