1、Creating ActiveX Controls for InTouch Using Microsoft Visual BasicCreating ActiveX Controls for InTouch Using Microsoft Visual BasicAll Tech Notes and KBCD documents and software are provided as is without warranty of any kind. See the Terms of Use for more information.Topic#: 001010Created: Decembe
2、r 6, 2001IntroductionThis document will help users understand how to leverage ActiveX technology to create add-on controls to be used inside InTouch applications. Many programming tools can be used to create ActiveX controls, one of the most popular being Visual Basic (VB). It is asumed that you hav
3、e a working knowledge of Visual Basic.The first part of this document presents some key concepts in ActiveX; the second section shows how to actually use VB to create a sample ActiveX control.Note: This document is not intended to explain, in just a few pages, how ActiveX controls work, but rather t
4、o give an overview of ActiveX and how to create a simple control in VB. Please refer to the Microsoft VB documentation and MSDN for complete details.Part A - Theory of ActiveX Controls and InTouch ActiveX ContainerActiveX Controls - A Short DefinitionInter-process/Inter-node communication and intera
5、ction between different software packages are the driving force behind Dynamic Data Exchange (DDE), Object Linking and Embedding (OLE), Component Object Model (COM, DCOM, COM+), and ActiveX, among other technologies.An ActiveX control is a COM object that supports a customizable, programmatic interf
6、ace using the methods, events, and properties exposed. Because ActiveX Controls are not executable programs, they must be instantiated and used inside other applications called ActiveX containers. Examples of ActiveX containers include Internet Explorer, Microsoft Office, and windows in InTouch appl
7、ications.ActiveX Controls TheoryInterfaces: Properties, Methods, and EventsActiveX containers and ActiveX controls communicate via interfaces that the controls expose to the outside world. An interface can include a number of Properties, Methods, and Events. Properties define the behavior of the con
8、trol. For example, Color, Font, Size, and Data Source Name can be properties exposed by a control. When ActiveX controls are used inside InTouch, Properties can be bound to tagnames in different ways, as will be shown later. Methods are functions exposed by the control that allow the container to tr
9、igger actions inside the control. To call a method, reference the name of the control, then the name of the function: MyControl3.Connect, YourControl1.CalAvg(1,2,3), #ThatControl7.Do Stuff(); (This last example shows the proper syntax inside InTouch scripts.) Events allow an ActiveX Control to signa
10、l to its container when an Event takes place inside the control. For example, Click, MouseMove, or DoneIt.Other concepts involving ActiveX controls include Identification, Encapsulation, Property Pages, Persistence, and Compatibility. These are briefly explained in the following paragraphs.GUIDsComp
11、onents in Microsoft Windows, which include ActiveX controls, have a 128-bit unique identification known as the Globally Unique IDentifier (GUID). GUIDs are based on the Date, Time, and the PC where they are generated (the algorithms used to create the GUIDs were designed by the Open Software Foundat
12、ion -OSF Distributed Computing Environment -DCE). GUIDs identify entries in the Windows registry, such as ActiveX controls, classes, Interfaces, and so on. For example, the GUID for the Calendar control included with MS Office XP is stored in the registry as:HKEY_CLASSES_ROOTCLSID8E27C92B-1264-101C-
13、8A2F-040224009C02Encapsulation: Containment and AggregationActiveX controls can have embedded ActiveX Controls. In that case, the outer control is called a Composite control and the inner controls are constituent controls. Containment takes place when a control exists within another control. Aggrega
14、tion (or delegation) is when the external control uses the constituent controls interface as its own. It is transparent to the client (container) who does the actual job. The concept of encapsulation is presented in the practical section of this Tech Note.Encapsulation is important because it allows
15、 the use of ActiveX controls inside InTouch when they expose properties other than the basic types that are supported in InTouch 7.x, i.e., Discrete, Integer, Real, and Message. The unsupported control can be used as a constituent control for another control that limits the properties to fore-mentio
16、ned types.Property PagesActiveX controls and containers typically include windows or dialog boxes to view and set the properties; these windows are called Property Pages. InTouch, an ActiveX container, has a tabbed dialog box that displays user-defined properties or container-defined properties; All
17、 controls inside InTouch have default properties that include ControlName, position (Left, Top, Width, Height), and Visible (in Runtime) as shown in Figure 1.Visual Basic, another ActiveX container, includes Font, Color, and Picture as default properties.Figure 1: Default Properties in the InTouch 7
18、.x ActiveX ContainerPersistencePersistence allows components to save and later retrieve data. Most containers support IPersistPropertyBag, an intrinsic interface that greatly simplifies the process of reading and writing data for controls. ActiveX controls in Visual Basic include a number of methods
19、, such as WriteProperties and ReadProperties to invoke the PropertyBag object.For example, the following line saves Wonderware to the m_strCompany string property:PropBag.WriteProperty (Wonderware, mbytMyData)CompatibiltyA compiled ActiveX control includes GUIDs for the control itself and for any ob
20、ject classes or interfaces that it implements. Containers use the class ID to request the control to create an object, and then query the object for the interface ID (IID); an error occurs if it is not found.By default, Visual Basic sets the compatibility for ActiveX controls to Project Compatibilit
21、y, which means new IDs are generated after each recompilation (see Figure 2). Once a control is released, it is recommended to switch from Project (or No Compatibility) to Binary Version Compatibility. Please refer to MSDN or the Visual Basic documentation for more details.One Golden rule in COM is
22、that you must never change an objects interface once it has been compiled and released because you could be breaking applications that use the object. Create new objects if necessary, and name them with a suffix that identifies subsequent releases: MyObject2, MyObject3, and so on.Figure 2: Default V
23、ersion Compatibility in VB ActiveX Control ProjectsInTouch as an ActiveX ContainerInTouch 7.x handles ActiveX controls as if they are wizards. Wiz.ini is a file in the InTouch directory that keeps track of what wizards have been installed in WindowMaker. Note the difference between registration of a
24、n ActiveX control in Microsoft Windows (via regsvr32) and installation. Registration makes any container capable of creating instances of a control; installation in WindowMaker allows the control to be configured. Here is an example of the Wiz.ini entries with 4 ActiveX controls installed:Group0001C
25、ount=4Name=ActiveX ControlsItem0001=OCXGOT, 1Item0002=OCXGOT, 2Item0003=OCXGOT, 3Item0004=OCXGOT, 4Unlike with regular InTouch wizards, the entries in the Wiz.ini do not indicate by name which ActiveX control is which; that job is done in the Ocx.ini file. Ocx.ini indicates the name and GUID for the
26、 installed controls. For example:ActiveX ControlsCount=4Item0001=8BD21D60-EC42-11CE-9E0D-00AA006002F3,Microsoft Forms 2.0 ToggleButtonItem0002=8BD21D10-EC42-11CE-9E0D-00AA006002F3,Microsoft Forms 2.0 TextBoxItem0003=EAE50EB0-4A62-11CE-BED6-00AA00611080,Microsoft Forms 2.0 TabStripItem0004=79176FB0-B
27、7F2-11CE-97EF-00AA006D2776,Microsoft Forms 2.0 SpinButtonWiz.ini and Ocx.ini are text files stored in the InTouch installation directory and apply to any InTouch application. In contrast, ITGUID.cfg and ITOcx.cfg are binary files that are application-specific. These files keep track of what ActiveX
28、controls have been used (and how many times) in the application, so that unique names are guaranteed and a new name generated when creating a new instance of a control.LimitationsDevelopers often compare InTouch ActiveX containers with other containers, such as Microsoft Internet Explorer or Visual
29、Basic. It is very important to understand that not all containers include the same functionality, and InTouch has a number of limitations that must be observed when creating ActiveX controls for InTouch applications: Supported Data TypesOnce again, remember that InTouch does not support data types o
30、ther than Discrete (boolean), Integer (32-bit numbers), Real (floating point IEEE notation with 32 bits), and Message (strings up to 131 characters). Unsupported data types include variant, pointers, arrays, structures, and parameterized properties.If you are planning to use an ActiveX control that
31、exposes properties, methods, and events that do not meet the requirements for InTouch data types, you need to create an ActiveX Control that encapsulates, or wraps the original ActiveX control and massages the unsupported property so that InTouch can use it. It is very easy to create properties and
32、methods for a wrapper (external) control that are mapped to properties and methods in the constituent (internal) control. The following is an example of a wrapper function to encapsulate an unsupported function that uses the Variant data type.Member variable defined as variantDim m_Prop1 As Variant.Public Function WrapperFunction() As String Dim MyVariant As Variant MyVariant = UnsupportedFunction(m_Prop1) WrapperFunction = MyVariantEnd FunctionPublic Function UnsupportedFunction(ByVal
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1