Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx

上传人:b****6 文档编号:6621154 上传时间:2023-01-08 格式:DOCX 页数:18 大小:174.77KB
下载 相关 举报
Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx_第1页
第1页 / 共18页
Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx_第2页
第2页 / 共18页
Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx_第3页
第3页 / 共18页
Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx_第4页
第4页 / 共18页
Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx

《Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx》由会员分享,可在线阅读,更多相关《Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx(18页珍藏版)》请在冰豆网上搜索。

Creating ActiveX Controls for InTouch Using Microsoft Visual Basic.docx

CreatingActiveXControlsforInTouchUsingMicrosoftVisualBasic

CreatingActiveXControlsforInTouchUsingMicrosoftVisualBasic

AllTechNotesandKBCDdocumentsandsoftwareareprovided"asis"withoutwarrantyofanykind.SeetheTermsofUseformoreinformation.

Topic#:

001010

Created:

December6,2001

Introduction

ThisdocumentwillhelpusersunderstandhowtoleverageActiveXtechnologytocreateadd-oncontrolstobeusedinsideInTouch™applications.ManyprogrammingtoolscanbeusedtocreateActiveXcontrols,oneofthemostpopularbeingVisualBasic(VB).ItisasumedthatyouhaveaworkingknowledgeofVisualBasic.

ThefirstpartofthisdocumentpresentssomekeyconceptsinActiveX;thesecondsectionshowshowtoactuallyuseVBtocreateasampleActiveXcontrol.

Note:

Thisdocumentisnotintendedtoexplain,injustafewpages,howActiveXcontrolswork,butrathertogiveanoverviewofActiveXandhowtocreateasimplecontrolinVB.PleaserefertotheMicrosoftVBdocumentationandMSDNforcompletedetails.

PartA-TheoryofActiveXControlsandInTouchActiveXContainer

ActiveXControls-AShortDefinition

Inter-process/Inter-nodecommunicationandinteractionbetweendifferentsoftwarepackagesarethedrivingforcebehindDynamicDataExchange(DDE),ObjectLinkingandEmbedding(OLE),ComponentObjectModel(COM,DCOM,COM+),andActiveX,amongothertechnologies.

AnActiveXcontrolisaCOMobjectthatsupportsacustomizable,programmaticinterfaceusingthemethods,events,andpropertiesexposed.BecauseActiveXControlsarenotexecutableprograms,theymustbeinstantiatedandusedinsideotherapplicationscalledActiveXcontainers.ExamplesofActiveXcontainersincludeInternetExplorer,MicrosoftOffice,andwindowsinInTouchapplications.

ActiveXControlsTheory

Interfaces:

Properties,Methods,andEvents

ActiveXcontainersandActiveXcontrolscommunicateviainterfacesthatthecontrolsexposetotheoutsideworld.AninterfacecanincludeanumberofProperties,Methods,andEvents.

∙Propertiesdefinethebehaviorofthecontrol.Forexample,Color,Font,Size,andDataSourceNamecanbepropertiesexposedbyacontrol.WhenActiveXcontrolsareusedinsideInTouch,Propertiescanbeboundtotagnamesindifferentways,aswillbeshownlater.

∙Methodsarefunctionsexposedbythecontrolthatallowthecontainertotriggeractionsinsidethecontrol.Tocallamethod,referencethenameofthecontrol,thenthenameofthefunction:

MyControl3.Connect,YourControl1.CalAvg(1,2,3),#ThatControl7.DoStuff();(ThislastexampleshowsthepropersyntaxinsideInTouchscripts.)

∙EventsallowanActiveXControltosignaltoitscontainerwhenanEventtakesplaceinsidethecontrol.Forexample,Click,MouseMove,orDoneIt.

OtherconceptsinvolvingActiveXcontrolsincludeIdentification,Encapsulation,PropertyPages,Persistence,andCompatibility.Thesearebrieflyexplainedinthefollowingparagraphs.

GUIDs

ComponentsinMicrosoftWindows,whichincludeActiveXcontrols,havea128-bituniqueidentificationknownastheGloballyUniqueIDentifier(GUID).GUIDsarebasedontheDate,Time,andthePCwheretheyaregenerated(thealgorithmsusedtocreatetheGUIDsweredesignedbytheOpenSoftwareFoundation-OSFDistributedComputingEnvironment-DCE).GUIDsidentifyentriesintheWindowsregistry,suchasActiveXcontrols,classes,Interfaces,andsoon.Forexample,theGUIDfortheCalendarcontrolincludedwithMSOfficeXPisstoredintheregistryas:

HKEY_CLASSES_ROOT\CLSID\{8E27C92B-1264-101C-8A2F-040224009C02}

Encapsulation:

ContainmentandAggregation

ActiveXcontrolscanhaveembeddedActiveXControls.Inthatcase,theoutercontroliscalledaCompositecontrolandtheinnercontrolsareconstituentcontrols.

∙Containmenttakesplacewhenacontrolexistswithinanothercontrol.

∙Aggregation(ordelegation)iswhentheexternalcontrolusestheconstituentcontrol'sinterfaceasitsown.

Itistransparenttotheclient(container)whodoestheactualjob.TheconceptofencapsulationispresentedinthepracticalsectionofthisTechNote.

EncapsulationisimportantbecauseitallowstheuseofActiveXcontrolsinsideInTouchwhentheyexposepropertiesotherthanthebasictypesthataresupportedinInTouch7.x,i.e.,Discrete,Integer,Real,andMessage.Theunsupportedcontrolcanbeusedasaconstituentcontrolforanothercontrolthatlimitsthepropertiestofore-mentionedtypes.

PropertyPages

ActiveXcontrolsandcontainerstypicallyincludewindowsordialogboxestoviewandsettheproperties;thesewindowsarecalledPropertyPages.

InTouch,anActiveXcontainer,hasatabbeddialogboxthatdisplaysuser-definedpropertiesorcontainer-definedproperties;AllcontrolsinsideInTouchhavedefaultpropertiesthatincludeControlName,position(Left,Top,Width,Height),andVisible(inRuntime)asshowninFigure1.

VisualBasic,anotherActiveXcontainer,includesFont,Color,andPictureasdefaultproperties.

Figure1:

DefaultPropertiesintheInTouch7.xActiveXContainer

Persistence

Persistenceallowscomponentstosaveandlaterretrievedata.MostcontainerssupportIPersistPropertyBag,anintrinsicinterfacethatgreatlysimplifiestheprocessofreadingandwritingdataforcontrols.ActiveXcontrolsinVisualBasicincludeanumberofmethods,suchasWritePropertiesandReadPropertiestoinvokethePropertyBagobject.

Forexample,thefollowinglinesaves"Wonderware"tothem_strCompanystringproperty:

PropBag.WriteProperty("Wonderware",mbytMyData)

Compatibilty

AcompiledActiveXcontrolincludesGUIDsforthecontrolitselfandforanyobjectclassesorinterfacesthatitimplements.ContainersusetheclassIDtorequestthecontroltocreateanobject,andthenquerytheobjectfortheinterfaceID(IID);anerroroccursifitisnotfound.

Bydefault,VisualBasicsetsthecompatibilityforActiveXcontrolstoProjectCompatibility,whichmeansnewIDsaregeneratedaftereachrecompilation(seeFigure2).Onceacontrolisreleased,itisrecommendedtoswitchfromProject(orNoCompatibility)toBinaryVersionCompatibility.PleaserefertoMSDNortheVisualBasicdocumentationformoredetails.

OneGoldenruleinCOMisthatyoumustneverchangeanobject’sinterfaceonceithasbeencompiledandreleasedbecauseyoucouldbebreakingapplicationsthatusetheobject.Createnewobjectsifnecessary,andnamethemwithasuffixthatidentifiessubsequentreleases:

MyObject2,MyObject3,andsoon.

Figure2:

DefaultVersionCompatibilityinVBActiveXControlProjects

InTouchasanActiveXContainer

InTouch7.xhandlesActiveXcontrolsasiftheyarewizards.Wiz.iniisafileintheInTouchdirectorythatkeepstrackofwhatwizardshavebeeninstalledinWindowMaker.NotethedifferencebetweenregistrationofanActiveXcontrolinMicrosoftWindows(viaregsvr32)andinstallation.Registrationmakesanycontainercapableofcreatinginstancesofacontrol;installationinWindowMakerallowsthecontroltobeconfigured.HereisanexampleoftheWiz.inientrieswith4ActiveXcontrolsinstalled:

[Group0001]

Count=4

Name=ActiveXControls

Item0001=OCXGOT,1

Item0002=OCXGOT,2

Item0003=OCXGOT,3

Item0004=OCXGOT,4

UnlikewithregularInTouchwizards,theentriesintheWiz.inidonotindicatebynamewhichActiveXcontroliswhich;thatjobisdoneintheOcx.inifile.Ocx.iniindicatesthenameandGUIDfortheinstalledcontrols.Forexample:

[ActiveXControls]

Count=4

Item0001={8BD21D60-EC42-11CE-9E0D-00AA006002F3},MicrosoftForms2.0ToggleButton

Item0002={8BD21D10-EC42-11CE-9E0D-00AA006002F3},MicrosoftForms2.0TextBox

Item0003={EAE50EB0-4A62-11CE-BED6-00AA00611080},MicrosoftForms2.0TabStrip

Item0004={79176FB0-B7F2-11CE-97EF-00AA006D2776},MicrosoftForms2.0SpinButton

Wiz.iniandOcx.iniaretextfilesstoredintheInTouchinstallationdirectoryandapplytoanyInTouchapplication.Incontrast,ITGUID.cfgandITOcx.cfgarebinaryfilesthatareapplication-specific.ThesefileskeeptrackofwhatActiveXcontrolshavebeenused(andhowmanytimes)intheapplication,sothatuniquenamesareguaranteedandanewnamegeneratedwhencreatinganewinstanceofacontrol.

Limitations

DevelopersoftencompareInTouchActiveXcontainerswithothercontainers,suchasMicrosoftInternetExplorerorVisualBasic.Itisveryimportanttounderstandthatnotallcontainersincludethesamefunctionality,andInTouchhasanumberoflimitationsthatmustbeobservedwhencreatingActiveXcontrolsforInTouchapplications:

∙SupportedDataTypes

Onceagain,rememberthatInTouchdoesnotsupportdatatypesotherthanDiscrete(boolean),Integer(32-bitnumbers),Real(floatingpointIEEEnotationwith32bits),andMessage(stringsupto131characters).Unsupporteddatatypesincludevariant,pointers,arrays,structures,andparameterizedproperties.

IfyouareplanningtouseanActiveXcontrolthatexposesproperties,methods,andeventsthatdonotmeettherequirementsforInTouchdatatypes,youneedtocreateanActiveXControlthatencapsulates,or"wraps"theoriginalActiveXcontroland"massages"theunsupportedpropertysothatInTouchcanuseit.Itisveryeasytocreatepropertiesandmethodsforawrapper(external)controlthataremappedtopropertiesandmethodsintheconstituent(internal)control.

ThefollowingisanexampleofawrapperfunctiontoencapsulateanunsupportedfunctionthatusestheVariantdatatype.

'Membervariabledefinedasvariant

Dimm_Prop1AsVariant

...

PublicFunctionWrapperFunction()AsString

   DimMyVariantAsVariant

   MyVariant=UnsupportedFunction(m_Prop1)

   WrapperFunction=MyVariant

EndFunction

PublicFunctionUnsupportedFunction(ByVal

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 节日庆典

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1