May 1998

MDI 101

by Gerry Myers

The structure of a Windows application falls into one of three categories: SDI (Single Document Interface), MDI (Multiple Document Interface), or Dialog-as-main-window interface. The easiest way to understand SDI and MDI is to think about a word-processing program. An SDI application is something like Notepad or Write. In these programs, you can open and work in only one text file (document) at a time. Before you can open another document, you must close the current document--hence the name Single Document Interface. SDI applications are fairly straightforward to write; the menu is generally static, and your data comes and goes from only one data file.

An MDI word-processor would operate something like MS Word, AmiPro or WordPerfect. These programs let the user have several documents open at a time. Because users can work on several files (documents) simultaneously in MDI applications, they find such programs more convenient. Cutting and pasting between two documents is much easier in MDI since both files can be open. (You can cut and paste in SDI applications, but there's no drag-and-drop option.)

An MDI application is somewhat harder to write than other kinds of programs, since the menu can change depending on which open document has focus. In addition, you must take care not to put data in the wrong open file.

Both SDI and MDI mention a document. We generally think of a document as a disk file, but it can really be anything that can give and get data. A communications port can be a document, as can a PC sound system. In our word-processing analogy, a document is indeed a disk file containing textual information.

The use of the term document to differentiate the two application types (SDI versus MDI) isn't completely accurate. What sets MDI apart from SDI is the fact that MDI applications have child windows. All the display work in an SDI application takes place right on the application's main window. However, in an MDI application, you generally draw nothing on the main window--all presentation takes place on child windows displayed within the borders of the main window (the parent window). Actually, in a multiple document interface application, you can view the data from a single open document (disk file) in different ways through different child windows (one document, multiple child windows). This ability to contain child windows draws the line between MDI and SDI.

I've used a word-processing analogy for discussion purposes only. This example in no way means that SDI and MDI apply only to word processing. It would be safe to argue that the initial use of the term document sprang from Microsoft's Word and Excel projects back during the early days of Windows 3.x, and then it stuck. Nevertheless, developers are using the SDI and MDI structures for nearly every Windows program regardless of the type of data and where the data comes from.

Just for completeness, let me mention the Dialog-as-main-window interface, which appears in applications like Windows 95's Add/Remove Programs control panel. When you start such an application, the main window that opens is a dialog box. A dialog box generally doesn't have a menu, but is populated with buttons, list boxes, edit boxes, check boxes, and so on. Such programs are fairly straightforward to write.