Home Articles Books Downloads FAQs Tips

Q: Create an MDI menu that lists open MDI windows.


Answer

Most MDI programs contain a Window menu that lists all of the open MDI windows in a program. Figure 1 illustrates this menu item.

An MDI Window menu

Figure 1: MDI Windows Menu.

C++Builder can create and maintain the window menu without requiring you to do any work. To add a window menu to your MDI project, follow these steps:


Step 1: Add a menu item to the TMainMenu control that is on the MDI parent form. Set the Caption property of this item to &Window. Set the GroupIndex of this menu item to a high value to keep the window menu menu to the right of any child menu items that get merged into the main menu. Usually, you will add sub menu items under the window menu for tiling, cascading, and minimizing the MDI child windows.

Step 2: Bring up the MDI parent window in the Object Inspector. All forms have a property called WindowMenu. This property is a TMenuItem pointer that tells the VCL which menu item will act as the MDI window menu. Use the combobox provided in this property to select the window menu item that you created in step 1.


That's it. Run the program and see if it works. Notice that the window items appear automatically. Also notice that you don't have to write any code to activate an MDI child when it is selected from the menu.

Note: If you want your window menu to contain items for tiling and cascading the MDI children, you will have to code those OnClick handlers yourself. TForm provides functions that can help you do the work: Tile, Cascade, ArrangeIcons. If you use the MDI project wizard in the Object Repository, this code is created for you by C++Builder.

Note: If you create your project using the MDI project wizard in the Object Repository, the WindowMenu property will be configured for you.



Copyright © 1997-2000 by Harold Howe.
All rights reserved.