When the end user issues commands to build or run the application, Visual Basic calls several interfaces in the designer to create a run-time object.
First, Visual Basic calls IProvideClassInfo or IProvideDynamicClassInfo to get the type information it needs to create the object.
Next, before compiling the application or shifting into run mode, Visual Basic checks the value of the DESIGNERFEATURE_BEFORERUN flag in the registry. If the flag is set, indicating that the designer implements the IDesignerDebugging::BeforeRun method, Visual Basic calls this method.
In addition, Visual Basic asks the ActiveX designer to save the prototypical instance state for the run-time object. If the visual designer implements the IActiveDesigner interface, Visual Basic calls its SaveRuntimeState method to save the data. If not, Visual Basic uses the Save method of the visual designer's persistence interface, in the following order of preference:
Persistence and the IActiveDesigner interface are described in Chapter 7, "Persisting, Saving, and Debugging an ActiveX Designer."
On the Debugging tab of the Project Properties sheet, the user can denote one of the designers in the project as the Start component. If the user does so, Visual Basic calls that designer's IDesignerDebugging::GetStartupInfo method to determine which host to launch for the debugging session.
The exact steps that Visual Basic follows to create the ActiveX designer's run-time object depend on the requirements of the designer itself, as specified in the DesignerFeatures key in the registry.
The following is a sample registry entry for an ActiveX designer:
HKEY_CLASSES_ROOT\CLSID\<clsid>
\MiscStatus
OLEMISC_SETCLIENTSITEFIRST
\DesignerFeatures
Required
DESIGNERFEATURE_PREDECLAREDID
DESIGNERFEATURE_CANBEPUBLIC
DESIGNERFEATURE_DELAYEVENTSINKING
In the sample, the designer sets three required designer flags and no optional flags. The next figure shows the steps Visual Basic takes at run time to create the run-time object for this ActiveX designer:
The following steps describe how Visual Basic creates the run-time object:
An end user can create additional instances of a class defined by an ActiveX designer by using the New operator in Visual Basic code. Like the Forms class, but unlike ActiveX controls and public class modules, the classes produced by ActiveX designers are private classes by default.
If the designer sets the DESIGNERFEATURE_CANBEPUBLIC flag in the registry, an end user can specify that the class is public (like ActiveX controls and public class modules). To allow a public designer to be created with the New keyword in Visual Basic, the designer must also set DESIGNERFEATURE_CANCREATE in the registry. If the designer specifies both DESIGNERFEATURE_MUSTBEPUBLIC and DESIGNERFEATURE_CANBEPUBLIC, the class must be public; an end user cannot make it private.
After execution completes, Visual Basic checks the value of the DESIGNERFEATURE_AFTERRUN flag in the registry. If the flag is set, indicating that the designer implements the IDesignerDebugging::AfterRun method, Visual Basic calls this method.