Compartir a través de


Modifying a Control's Run-Time Behavior

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Visual Studio 2017 Documentation. After you insert a control and generate one or more wrapper classes, you can invoke the control's methods and program the control's event handlers.

The control's wrapper classes specify the functions you can use to modify the run-time behavior of the control. Include the appropriate wrapper class header file and use the methods. To set a property, look for an accessor method with the property name prefixed by Set. To retrieve a property, look for an accessor method with the property name prefixed by Get. Event handlers can be written later.

Because the controls are implemented using Automation, the types passed can only be Automation-safe types such as BSTR and VARIANT. While you can use system calls to allocate and set BSTRs and VARIANTs, you might want to use the ATL wrapper classes (CComBSTR, CComVariant), the Visual C++ COM Compiler support wrapper classes (_bstr_t, _variant_t), or the MFC wrapper class (COleVariant).

If you add a data control, the Insert ActiveX Control Wizard generates wrapper classes for the data control's coclasses that manage its internal data objects. These classes do not include all of RDO or ADO, but rather represent internal objects declared in the type library.

If you want to use ADO and RDO directly, you should connect to the ADO or RDO DLLs directly (Msado15.dll or Msrdo20.dll), either with the compiler COM support classes, which support the #import directive, or with the respective SDK.

To Set Control Properties at Run Time

Note that some properties of an ActiveX control might be read-only at run time, which makes dynamic creation difficult. You can temporarily simulate design mode for property initialization by overriding the control container's OnAmbientPropertyChange handler, as described in the Knowledge Base article, "How to: Set ActiveX Control Design-Time Properties at Run Time (Q260744)". You can find Knowledge Base articles at https://support.microsoft.com/.

See Also

Using ActiveX Controls