Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

ID: 23574, Multiple MDI Parent Forms in a single Application

by Remy Lebeau (TeamB) Email: Anonymous

This sample demonstrates how to allow a non-MDI project to host multiple MDI parent forms, none of which are the VCL's MainForm.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For C++Builder, Version 3.0  to 6.0 830 downloads
Copyright: Open Source or other

Size: 201,713 bytes
Updated on Wed, 24 Aug 2005 11:35:58 GMT
Originally uploaded on Wed, 24 Aug 2005 11:30:34 GMT
SHA1 Hash: 7E54BB5E4773044D6EDD6CB0CDD371B60393352A
MD5 Hash: EFF66909A9296D7F43661CEEF481FD62

    Explore the files in this upload

The VCL does not natively allow forms other than the MainForm to host MDI child forms. This is a hard-coded limitation on Borland's part, not a limitation in Microsoft's MDI architecture. Microsoft allows multiple windows in an application to host MDI children. There is no concept of MainForms in the Win32 API.

The VCL prevents forms other than the MainForm from being able to utilize FormStyle=fsMDIForm. The VCL only allows the MainForm to host MDI child forms. If the MainForm does not have FormStyle=fsMDIForm then the VCL throws an exception when creating an instance of a TForm that has FormStyle=fsMDIChild.

However, there is no limitation in the VCL that prevents forms with FormStyle=fsMDIForm from creating the MDI client window that is needed to host MDI child forms. By overriding the CreateWindowHandle() method in a TForm with FormsStyle=fsMDIChild, the form no longer requires the MainForm to be the only fsMDIForm available.

The limitation has existed since the very beginning of the VCL (or at least since BCB/Delphi v3 anyway, as far as I can tell).

WARNING: Because the VCL is hard-coded to expect the MainForm to be the only form with FormsTyle=fsMDIForm assigned, there are a few aspects of the VCL that will not work properly when this workaround is used, as follows:

1) The MDIChildCount and MDIChildren properties of TCustomForm will not work properly. This is because both properties loop through the global TScreen::Forms[] collection looking for forms that have FormStyle=fsMDIChild without regard to proper parent/child relationships. You will have to keep track of and access your child forms manually.

2) When a child form's Caption is changed, the WindowMenu of the MDI parent form is not updated correctly because the WM_MDIREFRESHMENU message is only sent to the MainForm.

3) The IsMDIMsg() and IsKeyMsg() methods of TApplication only check with the MainForm when processing messages from the message queue.

4) any other side-effects I have not stumbled across yet.

If you have the VCL's source code installed, you can try patching those issues manually. Quality Central #12006 outlines the code changes that I think are necessary.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03