SDI and MDI Applications

As mentioned at the beginning of this chapter, SDI applications are Single Document Interface applications, and MDI applications are Multiple Document Interface applications. The real difference is simply how many documents you can have simultaneously open in your application.

Also recall that Microsoft Word is a good example of a MDI application, where as MS Notepad is an example of a SDI application. The one issue that was not previously addressed is defining exactly what a document is. You might assume that it is something like a text document or Microsoft Word document, and that assumption would be correct. However, a document can be other things as well. A document can be a paint screen, like in Adobe Photoshop™. Photoshop is a MDI application; you can view several images at one time. Each image is, in effect, a document.

The application wizard (Figure 16.43) allows you to easily create the basic framework for either an SDI application or a MDI application. The entire framework, including the menus, is created for you. You then simply have to add in the specific application code where needed. Because both SDI and MDI applications are rather open-ended application types with a plethora of possible applications, this chapter will simply walk you through the wizard. You can then use various resources in the appendices at the end of the book to find specific ideas you might want to implement in a MDI or SDI application.

click to expand
Figure 16.43: The application wizard with SDI apps.

The SDI framework

Step 1: Start the application wizard, you will choose the SDI application type (Figure 16.44).

click to expand
Figure 16.44: Choosing the container option.

For the next few steps of the application wizard, you will simply keep default settings—until you get to Step 3 of 6 on the application wizard. Here you will make one single change. You will select the container option.

What this does is allow your application to contain documents, thus the term container. Clearly, your application will have to contain other items to show text documents, image documents, or any other type of document you might be interested in.

Throughout the rest of the application wizard, you will select the default options, until you reach the final screen of the application wizard. However, it would be useful for you to take some time to examine Step 4 of 6 (Figure 16.45A).

click to expand
Figure 16.45A: Step 4 of 6 on the application wizard.

You have a number of useful items you can choose from here. Any of the items selected will be automatically created for you by the application wizard. Each of these items is quite useful for you. For example, recall the work done to add in a menu? Well, at this stage in the application wizard, if you select the menu box, then a menu will be created for you, with all the standard options you are used to seeing in menus (file, view, edit, etc.). You can also choose to have printing/print preview support, as well as a docking tool bar created for you. This is all very useful and takes care of the work for you.

When you get to the final screen of the application wizard, you will notice that there is a section titled Base Class. Recall from the previous discussions of object-oriented programming that a base class is the class that is inherited from. Inheritance is a major part of the Microsoft Foundation Classes, and, hence, Visual C++. Every application has some base class. If we simply change our base class to the CrichEditView, as shown in Figure 16.45B, your application will support actual writing and editing of text.

click to expand
Figure 16.45b: The CrichEditView base class.

When you are done with the application wizard, you will have a base Single Document Interface application (Figure 16.46A). All you will need to do is to fill in the specific code you need.

click to expand
Figure 16.46A: The SDI application.

Now, because you had previously used the CrichEditView class as your base class, you can write text, save text files, and open existing text files right in your application! You have just created a basic word processor without writing a single line of code (Figure 16.46B).

click to expand
Figure 16.46b: The simple word processor

This example should illustrate several significant points to you. The first thing you should notice is the sheer power of the application wizard. This simple word processor was created for you entirely by the application wizard. Secondly, you can see that your choice of base class for your application can be quite important. It was your choice of the CrichEditView class that provided the actual support for text files.

The MDI framework

Much of the MDI application is the same as the SDI application. For that reason, we won’t be going over all those details a second time. We will simply highlight the differences.

Step 2: Start the application wizard. Follow the application wizard as you did in the last example. You will, of course, select the Multiple Document Interface option on Step 1 of 6 (Figure 16.47).

click to expand
Figure 16.47: The MDI application.

You will also choose the container option on Step 3 of 6, just as you did in the SDI application. Keep the default options, just as you did in the SDI application. The real difference will come when you run the application (Figure 16.48). Of course, if you want support for text files, as your SDI application had, you will need to use the CrichEditView as your base class. You will notice that your program is set to display several documents simultaneously. If you will select File and New, a new blank document will be created.

click to expand
Figure 16.48: Running the MDI application

In both of these examples, we simply followed the application wizard and created a framework for either a SDI application or a MDI application. These examples are not fully functional, but they do illustrate the ease of setting up the framework of SDI and MDI applications. It is certainly possible to create Visual C++ applications without the application wizard. However, as you have already seen, the application wizard creates a number of useful items for you. Essentially, the application wizard allows you to focus on your own application-specific code, and not waste time creating toolbars, menus, and the like.

C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom © 2008-2017.
If you may any questions please contact us: