VS2012下创建ATL项目开发ActiveX控件_第1页
VS2012下创建ATL项目开发ActiveX控件_第2页
VS2012下创建ATL项目开发ActiveX控件_第3页
VS2012下创建ATL项目开发ActiveX控件_第4页
VS2012下创建ATL项目开发ActiveX控件_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、开发笔记一、VS2012下 创建ATL项目开发 ActiveX控件1、创建ATL项目ATL Project Wizard * A.TLProjert2OverviewApplication SettingsApplication SettingsApplicatnni type: £ynarnicdink library (DL1)Executable (EXE)Qi Sennce (B(ESupport options:R Alow rnerging of CfCxy/stul? code Support M=C0 Support COM+ LOH Support 匚omponmt

2、 registrarM Segjrity Development Lifecyde ISOL) checksFile type handler options: Ffe eKterision:Document da豁 name;A : Support COM+ 1.0 Support component registrar 必选,不然控件属性,方法无法在 .NET 项目中直接使用,需要通过COM接口去访问,显的很麻烦例如:在WINFORM 中添加axPanell控件(假如 AxPanel是开发好的 ActiveX控件),AxPanel有一个Backlmage属性,但是 axPanell并没有

3、Backlmage属性,原因是没有勾选 支持COM+B :勾选 Allow merging of proxy/stub core,不然为生成 2 个项目2、添加ATL控件Add CIaee - AHProject?ji Installed&ort by: Dfvutt丄 YiiEUftl C> +CLRATLC+tMFCt1 OnlineATI Simple ObjectATL Corrt/Dlhjfrie:Lncalion:$C4rch Tn-iitllcd TpnnplntH (Ctrl +-E fitsB-=>B®ATL OLE Db CansjumerAT

4、L DidchgAdd AIL Support To MFCATL Property PageATL OLEDB Pro widerATI Artwfl Serwr Pjge ComponentATLCOM+ LXJ CwnpanentVi孔alOtTyp«t Vkual U + *Add an Adiw Template Library ArtwX wntrolVisual C+ +Visual C+ +Visual C+ +Visual C+ +Visual 匚* +Visual C4 +Visual C+ +Visual C+F:1CIJXATLCDrrtrDlATLPrDje

5、rt2Cancel3、输入控件名称Welcome to the ATL Control WizardATLNamesOptio nsInterfacesAppearanceStock PropertiesC+-Short name:.h file:AxPanel. h.cpp file:AxPanel.cppCOMCodass:lype:AxPanel ClassProgID:Ctrl.AxPanel|< PreviousFinishCancel4、设置控件选项OptionsATLrJamesOptionsInterfacesAppeara 仃£Stock Properties

6、Control type: Standard control? Composite CQntrolDHTML mntrolJ Minimal controlAggregation:® eso如-'OnlyInterface: DualCustomI | Automation compatibleSupport:0 Connection 四intsLicensedClick here fbr unsupported Smart Device Options< PreviousNest >FinishCancel注意:勾选Connection points,其他默认5

7、、设置接口ATLNamesOptio nsInterfacesAppeara 仃£Stock PropertiesNot supported:IObjectWithSitsIServiceProviderISpedfyPropertyPages'>>*<<IDataObjectIObjectSafiety IPersistStorage IPersistStreamlnitIPropertyNotifySink IProvideClassInfoZIQuickActivateISupportErrorlnfbInterfacesClick here f

8、or unsupported Smart Device Options< PreviousNest >FinishCancel添加IPersistStreamlnit (WINFORM 中解决AxHost问题,必须添加,不然控件初始化就异常)IPersistStorage,IPropertyNotifySink,IObjectSafety(IE中不在提示安全问题)6、显示AppearanceATLNamesOptionsInterfacesAppearanceStock PropertiesView status:0 Opaque0 Solid backgroundAdd cont

9、rol based on:(n one)vOther:11 Normalized DC0 Windowed onlyI I InsertableMiscellan皂ouss status:I I Invisible at run timeI I Acts like buttonI I Acts like labelClick here for unsupported Smart Device Options< PreviousNext >FinishCancel注意:控件的话,就勾选Win dowed only吧,不然就不会触发 On Create7、属性的话就看自己喜好勾选了St

10、ock PropertiesATLNamesOptio nsInterfacesAppears 仃 ueStock PropertiesNot supported:earanceAuto SizeBackground ColorBackground Style Border Color Border Style Border VisibleSupported:Border WidthCaptionDraw ModeDraw StyleDraw WidthClick here for unsupported Smart Device Options< PreviousNext >Fi

11、nishCancel7、点击完成(Finish)完成后Build 一次项目(管理员模式或者项目属性中,register out改为NO),然后继续8、为了使用属性,还必须在代码里两处地方添加如下代码class ATL_NO_VTBLE CAxPanel :pub lie CCoinObj ectR&otE x<CCcm5 in gleThrcd dModel> fpublic publicIDispatchlnpl<lAxPanel&IID lAxPahelj &.LIBID ATiLProjeet2Libj, /rftajor */ 丄./*n#1i

12、nor ©>,WWWWlWWWHWWWWh *,WVVhrtrtWVWWV4rtRiilWWWnrt *JrrIPerEist£treamiInitIimpl<CAxPanel>pub lie 10 leCont roll mpl <CAxPane 1>>pub 1 ic ICleOb-jectlmpl<CAxPane 1 >fpub lie iolel nPlac e-Act iveobj ect I mpKCAxP anel>j public IViewObjectExlBpl<CAxPanel>>

13、pub 1 ic lOlelnPla匚eObjectkindorieselimp 1<CAxPanel>j public ISupportErr-orlnfqpub 1 ic IConnectio-nPointtontaifierlrrpl<CAxPanel>#public CProxy_IAxRanelEvents<CAxPanel pub lie I Pers is tP rope r tyBagl mp 1 c CAxPane public IPerEistStoragelrrplCAxPanelJj, pub lie ZQuic kAct ivite Im

14、pme 1、.BEGIN_COM_MAP(CAxPanel)COM_IHTERFACE_EHTR¥(IAxPanel)COMINTERFACEENTHY(IDispatch)OM_INTERFACE_ENTRY (IVieiOb ject Ex)COM_INTERFACE_ENTRYClVieivObject2)COMINTERFACEEhTftY(iViewObject)C0M_irTTERFACE_Er<rRY(I01eInPlaceObjectWindowles5) COM_INTERFACE_ENTRYClOLeInPlaceObject)CoCrNTERFACEIEW

15、TftY2(I01el irido IGlelnPlaceObjectlJindowless)C0M_IKTERFACE_EWrRY(IOleInPlaceActive0bject)COTLINTERFACEENTRYClOLeControl)COMINTERFACEEhTRYflOLeObject)COM_IIMTERFACE_ENTRY( I Persists日 mTnitCOTLINTERFACEENTRYZtlPersistj IPersistStreamlnit)C0M_INTERFACE7EhTR¥(ISupportE rrorinfo)CaMlNTERFACEENTRY

16、(IConnectionPointContainer)匸 OM_jrrrERF 胚 E_EHTR¥(TPtcistPropert¥Bag)COM_INTERFACE_EMTRY(IQuickActivate)COH_lNTERFACE_ErJTRY(IPersistStc-age)9、在构造方法中添加匚 AxPanel( )|th is * >tn_bNindcwQn ly = true * 到此项目创建完毕,可以进行开发了。二、ATL属性,方法的添加1打开类视图(Class View),找到lAxPanel接口,右键-添加(Add)-添加属性(Add Propert

17、y)J + ATLProject2e<£earch>MapsGlobal Fiuncticns and VariablesMacros and ConstantsATLProject2LibCATLP roject2ModuleCAxanelP >r>七b 七匚Prcxy_IAxPan&lEwent <T>View Clas DiagramGo To DefinitionF12Go To DeclarationCtd+F12Browse DefinitionFind Alli ReferencesCtd+K, R%Filter Tq Typ

18、eAddB?CIbes Wizards.CtrlfShift+Xc°pyQri+CSort AlphabeticallySort Ey Object Type Sort By Object Access Group By Object TypePropertiesAlt+Enter6+m pone nt Registrar ?plicationl® Add Method. 么 Add Property-.Properties Team Explorer Class View2、选择属性类型,填写属性名称Welcome to the Add Property WizardPr

19、operty name:Backlmag 已NamesIDL AttributesProperty type:BSTRReturn type:Function type:Get functionHFLE5ULT inTAdd outRemovePropPufftefParameter type:P7 Put fun匚tion PropPutParameter name:< PreviousNext >FinishCancel3、设置属性的IDL属性IDL AttributesNamesIDL Attributesid:0 bindable| | defaultbind:dislay

20、bind:immediate bind:defaultcollelemnon browsablehelpcontext:0 reguesteditsource| | hiddenrestricted local< PreviousNext >FinishCancel4、在PROP_MA中添加代码BEGIN?ROPMAP(CAxPanel)PROP_DATA_ENTRY(,p_cx"j m sizeExtent. cx VT_UI4) PROP_DATA_EMTRY(cy"/ m_sizeExtent*VT_UI4)|PROP EMTR¥kjnim兑已AxPmn皀I,廿T 吕5TR)I / Example entriesH PROP_ENTRY_TYPE("Property Name' dispidj clsid vtType) H PROPHAGE(CLSID StockColorPage)ErJD_PROP_MAP()上面4个参数分别为,属性名,属性

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论