Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Fast Track Visual C++ 6.0 Programming (Publisher: John Wiley & Sons, Inc.) Author(s): Steve Holzner ISBN: 0471312908 Publication Date: 09/01/98 Search this book:
Previous | Table of Contents | Next
## Chapter 2 Multiple Documents, Multiple Views In this chapter, we explore the ins and outs of Multiple Document Interface (MDI) thoroughly. MDI programming is a relatively unique feature of the MFC, and it gives us a lot of power. MDI programming is our first step as we move progressively toward more advanced topics in this book. In this chapter, we begin by creating an MDI program that can accept multiline text input from the user and lets the user open not only multiple documents, but multiple views into those documents. We learn to coordinate a document’s views so when the user types in one view, the others are updated as well. We also use view hints to update views in a smart way and we learn how to set a document’s modified flag (also called a dirty flag) so that if the user tries to close a modified file, the program will prompt him or her to save it. Once we’re able to support multiple views in a document, we can learn how to implement scrolling. By implementing scrolling, the user will be able to open different views in the same document and move around in that document at will. There’s no reason multiple views should show the same part of the document; in fact, that would defeat the whole idea behind multiple views. We then continue by working with menus in MDI programs. We work with two sets of menus; which one is active depends on whether MDI child windows are open. We also look at how to access all the views connected to a document, how to use new document functions that we haven’t yet seen, and even how to write MDI programs that support different types of views in the same program; that is, we learn to support multiple view classes in the same program. Let’s get started at once by creating our first MDI program. ### Creating an MDI Program Our first MDI program, which we call MDI, lets the user type multiline text into documents.
             ------------------------------------------------------
            |                                                      |
            |                                                      |
            |------------------------------------------------------|
            |              ---------------------                   |
            |             |MDI1                 |                  |
            |             |---------------------|                  |
            |             |This                 |                  |
            |             |is                   |                  |
            |             |the                  |                  |
            |             |text                 |                  |
            |             |                     |                  |
            |              ---------------------                   |
            |                                                      |
            |                                                      |
            |                                                      |
             ------------------------------------------------------
The main window is called the MDI frame window, and the small document window inside is called an MDI child window. In addition to creating multiple documents, this program supports multiple views into each document. If you use the Window menu’s New Window item, the program opens a new view into the document currently active. Note that the program has given the name MDI1 to this document, so the first view becomes MDI1:1 and the second view MDI1:2:
             ------------------------------------------------------
            |                                                      |
            |                                                      |
            |------------------------------------------------------|
            |              ---------------------                   |
            |             |MDI1:1              |                   |
            |             |------------ ---------------------      |
            |             |This        |MDI1:2               |     |
            |             |is          |---------------------|     |
            |             |the         |This                 |     |
            |             |text        |is                   |     |
            |             |            |the                  |     |
            |              ------------|text                 |     |
            |                          |                     |     |
            |                           ---------------------      |
            |                                                      |
             ------------------------------------------------------
Naming Documents We learn to change the default name MDI programs give to documents later in this chapter. Changing the default file extension is covered in Chapter 5, “Real World Programming: The Editor Application.” Now, however, if we type into one of the views, the text appears only in that view, even if we update the document itself.
             --------------------------------------------------
            |                                                  |
            |                                                  |
            |--------------------------------------------------|
            |              ---------------------               |
            |             |MDI1:1              |               |
            |             |----------- ---------------------   |
            |             |This        |MDI1:2              |  |
            |             |is          |--------------------|  |
            |             |the         |This                |  |
            |             |text        |is                  |  |
            |             |            |the                 |  |
            |              ------------|text                |  |
            |                          |that I am typing... |  |
            |                           ---------------------  |
            |                                                  |
            ----------------------------------------------------
It is possible to coordinate multiple views in this program so that as you type in one view, what you type appears in the other view at the same time.
             -------------------------------------------------
            |                                                 |
            |-------------------------------------------------|
            |              ---------------------              |
            |             |MDI1:1              |              |
            |             |------------ -------------------   |
            |             |This        |MDI1:2            |   |
            |             |is          |------------------|   |
            |             |the         |This              |   |
            |             |text        |is                |   |
            |             |that I am ty|the               |   |
            |              ------------|text              |   |
            |                          |that I am typing..|   |
            |                          -------------------    |
            |                                                 |
             -------------------------------------------------
Figure 2.1 Creating an MDI project. Start Visual C++ now and create a new AppWizard(exe) project, naming it MDI. When AppWizard asks you what type of application you would like to create, leave the Multiple Document option button clicked, as shown in Figure 2.1, and click the Finish button to create the project. Let’s look at what AppWizard has written for us.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.