Freigeben über


Visual Basic Concepts

Displaying Forms from Code Components

Code components can display modal or modeless forms, subject to certain restrictions.

In-Process Components that Show Modeless Forms

Modeless forms displayed by in-process components cannot function correctly unless they can communicate with the client's message loop. Therefore, in-process components created with Visual Basic can display modeless forms only in client processes that support such communication.

The following applications support the display of modeless forms by in-process components:

  • Applications created with Visual Basic 5.0 or later.

  • Microsoft Office 97 or later.

  • Applications that have the Visual Basic Technology logo. (That is, that license Visual Basic for Applications version 5.0 or later.)

Applications that do not support the display of modeless forms by in-process components include:

  • Applications created with earlier versions of Visual Basic.

  • Earlier versions of Microsoft Office.

  • Version 3.x of Microsoft Internet Explorer.

Determining Support for Modeless Forms at Run Time

To allow in-process components to detect at run time whether a client application supports the display of modeless forms, Visual Basic provides the Boolean NonModalAllowed property of the App object.

An in-process component should test this property before showing a modeless form. If the value is True, the form can be shown vbModeless. If the value is false, showing a modeless form will cause run-time error 369. The component should degrade gracefully by showing the form vbModal instead.

Important Debugging Limitation

When you’re debugging an in-process component in the development environment, using a non–Visual Basic application as an out-of-process test program, modeless forms will appear to work even if the non-Visual Basic application doesn’t support them.

Testing the NonModalAllowed property of the App object is of no use in this situation; the property will return True regardless of the client. The reason for this is that when debugging an in-process component with an out-of-process test application, Visual Basic cannot determine whether the test application supports modeless forms.

Before attempting to write an in-process component that will show modeless forms, for use with a specific non–Visual Basic application, you should compile a small test DLL with a method that displays the value of the NonModalAllowed property of the App object in a message box. Call this method from the non-Visual Basic application, to determine whether it supports modeless forms.

Forms Displayed by Out-Of-Process Components

Modal and modeless forms displayed as a result of method calls to out-of-process components will not necessarily appear in front of the client application’s forms. The reason is that Automation does not define a z-order relationship between forms in different applications.

For More Information   "Creating an ActiveX EXE Component" provides a demonstration of the problems with showing forms from out-of-process components.