英文 VC程序中使用脚本引.docx

上传人:b****2 文档编号:2375675 上传时间:2022-10-29 格式:DOCX 页数:10 大小:20.83KB
下载 相关 举报
英文 VC程序中使用脚本引.docx_第1页
第1页 / 共10页
英文 VC程序中使用脚本引.docx_第2页
第2页 / 共10页
英文 VC程序中使用脚本引.docx_第3页
第3页 / 共10页
英文 VC程序中使用脚本引.docx_第4页
第4页 / 共10页
英文 VC程序中使用脚本引.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

英文 VC程序中使用脚本引.docx

《英文 VC程序中使用脚本引.docx》由会员分享,可在线阅读,更多相关《英文 VC程序中使用脚本引.docx(10页珍藏版)》请在冰豆网上搜索。

英文 VC程序中使用脚本引.docx

英文VC程序中使用脚本引

ActiveXScriptinginMFC

BySteveWampler

LikeMicrosoftInternetExplorer,yourapplicationscansupportVBScript(VisualBasicScriptingEdition)andJScript(JavaScript)withverylittleeffortonyourpart.MicrosofthasdonemostoftheworkbyprovidingVBScriptandJScriptenginesandbydefiningtheActiveXscriptingCOMinterfacesthatenableyoutousetheengineswithinyourapplications.

We'lltakeMicrosoft'sworkonestepfurtherwithanMFC-likeC++classcalledCScriptEnginethatimplementstheActiveXscriptinginterfacesinthecontextofasampleMFCapplication.

YoushouldbefamiliarwithMFCandautomation.Ifnot,readuponbothintheVisualC++onlinedocumentation.

NotethatforActiveXscriptingtoworkinyourMFCapplications,yourVisualC++environmentmustbeversion4.2b.The4.2bupgradepatchisavailablefromMicrosoftatunder"DownloadsandPatches."YoumustalsohavetheVBScriptandJScriptDLLsthatcomewithInternetExplorer.YoucandownloadtheDLLsfromMicrosoftat

WhyActiveXscripting?

--------------------------------------------------------------------------------

"AutomationenablesautomationclientssuchasVisualBasictouseyourapplications.ButwhywouldyouwantyourapplicationtosupportActiveXscriptingaswell?

Theanswerdependsonyourapplication."

--------------------------------------------------------------------------------

AutomationenablesautomationclientssuchasVisualBasictouseyourapplications.ButwhywouldyouwantyourapplicationtosupportActiveXscriptingaswell?

Theanswerdependsonyourapplication.

Forexample,ifyourapplicationisanActiveXcontrolcontaineryouruserswilllikelywanttowritescriptsthataccessthecontrols'automationevents,properties,andmethods.Yourusersmayalsowanttheirscriptsstoredwithintheapplication'sdocuments.Andfinally,theylikelywantachoiceinscriptinglanguages.ByaddingsupportforActiveXscripting,yourapplicationscandoallofthesethings.Let'sexamineasampleapplicationcalledScriptTesttoseehow.

TheScriptTestapplicationfromtheuser'sperspective

ScriptTestisaHello,World!

–typeapplication.It'sasimpleSingleDocumentInterface(SDI)applicationgeneratedusingtheMFCAppWizard.Here'swhatScriptTestlookslikeinaction:

ToeditandrunaScriptTestscript,youinvoketheEnterScriptdialogbyselectingRunfromtheScriptmenu.Here'swhattheEnterScriptdialoglookslike:

IntheScriptTypebox,youchooseVBScriptorJScript.Youenterthescript'stextintheScripteditcontrol.

Togiveitatry,downloadtheScriptTestapplicationfromtheVCDJweb-siteandrunit.Fromthemenubar,selectScriptandRun,andenterthefollowingVBScript:

SubSayGoodbye

Document.Text="Goodbye,World!

"

EndSub

SayGoodbye

PressOKtorunthescript.

ThisVBScriptdeclaresaSayGoodbyesubroutinethatsimplysetsthedocument'sTextproperty(describedshortly)to"Goodbye,World!

"ThescriptthencallstheSayGoodbyesubroutine.Afterrunningthescript,ScriptTestdisplays"Goodbye,World!

"

ScriptTestfromaprogrammer'sperspective

WeenabledActiveXscriptinginScriptTestintwosteps:

first,weaddanautomationmethod,andapropertyinScriptTest'sdocumentclass,CScriptTestDoc,gaveascriptsomethingtodo;second,twoC++classesenabledScriptTesttocreateanduseanActiveXscriptingengine.

Step1:

automatingtheScriptTestapplication.BeforeaddingsupportforActiveXscripting,weusetheVisualC++ClassWizardtoaddanautomationpropertycalledTextandamethodcalledMsgBox()toScriptTest'sCScriptTestDocclass.TheTextpropertyisheldinaCStringvariablewithinScriptTest'sdocumentclass.ItsvalueiswhatyouseewritteninScriptTest'swindow.

InVBScript,youcangetandsetthedocument'sTextpropertylikeso:

'gettheTextproperty

strText=Document.Text

'settheTextproperty

Document.Text="Goodbye,World!

"

TheMsgBox()methodtakesonestringparametercontainingthemessagetext.Forexample,theVBScriptstatementDocument.MsgBox("Goodbye,World!

")causestheScriptTesttodisplaythefollowingmessage:

Step2:

creatingandusingascriptingengine.TocreateanduseanActiveXscriptingengine,ScriptTestincludestheclassesCScriptEngineandCScriptTestScriptEngine.

--------------------------------------------------------------------------------

"TheCScriptEngineclassisanMFC-likewrapperaroundanActiveXscriptingengine.It'sgeneralenoughthatyoushouldbeabletoreuseitinotherMFCapplications."

-------------------------------------------------------------------------------

TheCScriptEngineclassisanMFC-likewrapperaroundanActiveXscriptingengine.It'sgeneralenoughthatyoushouldbeabletoreuseitinotherMFCapplications

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

当前位置:首页 > 医药卫生 > 基础医学

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

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