A typical illustration of a multiple document interface (MDI) application is a text editor that can open several files simultaneously. Visual Studio is an example of an MDI. Older versions of Microsoft Word used a MDI but the latest versions create a new instance of the application for each file.
Solution10 in the demonstration pack illustrates a MDI application whilst Solution11 presents a single document interface (SDI).
Solution21 illustrates an alternative basis for a MDI application using a Silverfrost Tab_Control. This is described at the end of this topic.
In order to create a MDI application, create a form in the standard manner using the Visual Studio form design view. In the properties of the form, set IsMdiContainer to True.
Now write Fortran code to display the application. This is based on vcCreateDialog@ and vcDisplayDialog@ as for any other application.
Typically the application will Open a file or create a New file and display it in the parent window's client area. The MDI child that is created is based on a form designed for the given type of file. This form is designed in the same way as any other form. The only difference is that (in the Fortran code) it is displayed by calling vcCreateMdiChild@ and vcShow@. This will normally take place in a callback function for the MDI parent. A MDI parent can be used to display different types of MDI children; for example, one for text files and another for image files.
A number of standard callbacks are designed for MDI applications. See standard callbacks for further details.
You can attach a menu to the design of a MDI container for use when there are no child windows attached. You can also attach a menu to the design of a child form in such a way that this replaces the menu for the container when a child of this type is the active MDI child. The simplest way to do this is to use the MergeType called MergeItems for each menu title in the MDI container and the MergeType called Replace for corresponding titles in the child menu. All other items have their default MergeType (Add). In this context a menu title is an item that appears in the menu bar and not in a drop down sub menu.
You can attach a toolbar to the design of a MDI container for use when there are no child windows attached. You can also attach a toolbar to the design of a child form and Visual ClearWin will automatically replace the toolbar for the container when a child of this type is the active MDI child. This is limited to the case where the container and each type of child has just one toolbar.
You can drag and drop files on to a MDI or SDI application. Typically files can be selected in the standard file Explorer and dragged to a Visual ClearWin application. To enable drag and drop in your application requires three steps.
a) In the design view of the form, select the form and then set its AllowDrop property to true.
b) In the main program of your Fortran code, set the static thread attribute by including the line:
c) If your program uses the "Open" standard callback on a menu item and/or a toolbar button then no additional programming is required because Visual ClearWin drag and drop uses the same mechanism. The "Open" standard callback requires you to call vcOnEvent@ for the events Create_Child and Open_Child and, within the callback, to get the file name by calling vcGetStringData@ using "#Filename". Multiple files can be dropped and each file raises the above two events in turn. Multiple files are handled in a natural manner in a MDI. By default a SDI would open and close each file in turn and leave the last file in the list open. For further information about the "Open" standard callback see Standard Callbacks.
For more information on how to get started with muliple and single document interfaces, run Solution10 and Solution11. These samples can be used as a template for your application.
Using a Tab_Control as a MDI
Solution21 in the demonstration pack shows you how to create a MDI application based on a Silverfrost Tab_Control.
The approach is largely the same as that for a traditional MDI application as described above but the client area takes the form of a Tab_Control. At design time, drop a Tab_Control on to your form and set the IsMdiContainer property to true. The tab pages of this control are used to display various documents at run time. In the design view, each type of document (e.g. plain text, WYSIWYG HTML or graphics) has its own form that is used as a repository for an associaed menu, toolbar and tab page. The tab page is placed in a TabControl or a Tab_Control. At run time, Visual ClearWin transfers these components to the main application as and when required.
Tab page documents can be opened and closed (as in Microsoft Visual Studio) and the menu can display currently open files as well as recently closed files. You can also drag and drop files on to this kind of application as described above.
For further information run and experiment with Solution21.