Using VC + + ATL to implement istylepdf COM plugin

Source: Internet
Author: User

This article describes a method for usingVC + + ATL (Active templatelibrary), usingispextensibilityinterface, foristylepdfJoin the function simpleCOMPlugins (addin), add visual parts such as toolbar buttons, and add a method for responding to events. We useVS2010to beistylepdfPlatform Development Plugin, of course, can also use otherVStools. The first step in developing a plug-in requires installationistylepdfClient , the client program includes theActiveXcontrol, this is the type library we need to use. If you do not have a client, go toheredownload. Here's the step-by-step introduction to development.  

1, inVisual C + +programming environment, use the wizard to generate a code namedPdfaddinof theATL COM AppwizardEngineering(Figure A):

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/7A/wKioL1PoYcOic7wyAAJyPHgE6UE942.jpg "title=" 1.jpg " alt= "Wkiol1poycoic7wyaajyphge6ue942.jpg"/>

in the settings of the wizard, use the default settings and select Next . Then click Finishso that an empty ATL Project is created (ii).

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/79/wKiom1PoYLzCzRqwAAHpmCCC640246.jpg "title=" 2.jpg " alt= "Wkiom1poylzczrqwaahpmccc640246.jpg"/>

 2 atl  

Select Menu project- > Add Class ..., The Class Wizard dialog box appears (iii), click ADD :

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/79/wKiom1PoYMjS6g2tAALt_Is-NDA030.jpg "title=" 3.jpg " alt= "Wkiom1poymjs6g2taalt_is-nda030.jpg"/>

pdfreader Fill in, this name is very important, the last compile generated file name must be named with this. The example shows the istylepdf.pdfreader " Span style= "font-family: ' The song Body '; Background-color:rgb (242,242,242);" > The last compiled control name is called istylepdf.pdfreader.spi (four), click next

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/7A/wKioL1PoYinT4BBVAAF_1kh3kd8897.jpg "title=" 4.jpg " alt= "Wkiol1poyint4bbvaaf_1kh3kd8897.jpg"/>

The file type option takes the default value. The settings for the Options page are set according to your needs whether the connection point andISupportErrorInfosupport, and other default values are used. (Five), click Finish. A basicCOMThe component is created and the project is compiled to see if it is normal. The control now has noistylepdfassociated with them. Next is the focus setting.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/79/wKiom1PoYR-ynOugAAGNyAIJtjs826.jpg "title=" 5.jpg " alt= "Wkiom1poyr-ynougaagnyaijtjs826.jpg"/>

3, inCpdfreaderimplemented in classispextensibilitythe interface: 
ispextensibility is aistylepdfa virtual interface class in the type library. Plug-in program'sCpdfreaderas long as several interfaces that inherit and implement the class can be associated with the host program. To add the inherited virtual interface class step below, first select Class View to findATLSimple Object class, right-click the pop-up menu, selectadd->implement Interface. Six

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/79/wKiom1PoYSujjY7pAAJ3KFbpfV4161.jpg "title=" 6.jpg " alt= "Wkiom1poysujjy7paaj3kfbpfv4161.jpg"/>

Select the type library name available istylepdf objectlibrary<1.0> You can also select interface, select , move to the Implementation interface class on the right, and click Finish. Seven.

650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/45/7A/wKioL1PoYlDyu_ Eeaahxogalm_k692.jpg "title=" 7.jpg "alt=" wkiol1poyldyu_eeaahxogalm_k692.jpg "/>

now automatically added ispextensibility interface function of the interface class, Span style= "Font-family:simsun;background-color:rgb (242,242,242);" >onconnection ondisconnection The main use of these two functions. Modify the output file name after compilation succeeds. Can be placed in The plugin will be loaded when the platform is launched. Currently plug-in what features are not implemented, so what do not see, the following introduction to add a toolbar.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/79/wKiom1PoYUPxvhvTAAIKCME329c738.jpg "title=" 8.jpg " alt= "Wkiom1poyupxvhvtaaikcme329c738.jpg"/>

4 , add a toolbar button:  

The Add toolbar button can be implemented in a function that is then connected to the program. the OnConnection parameter is a application top-level object through which all other objects can be obtained. Please refer to the object model. We define a variable to save the application pointer.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/7A/wKioL1PoYmqxlMFtAABJN1bvSNE683.jpg "title=" 9.jpg " alt= "Wkiol1poymqxlmftaabjn1bvsne683.jpg"/>

OnConnection the implementation of the following code:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/7A/wKioL1PoYnWh5C-MAALMYESCnYc352.jpg "title=" 10.jpg "alt=" Wkiol1poynwh5c-maalmyescnyc352.jpg "/>

CommandBar refer to the object model for a description of the function. The compile-and-run toolbar is added. Nine

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/79/wKiom1PoYWjAUybUAABy4GkXDjs130.jpg "title=" 11.jpg "alt=" Wkiom1poywjauybuaaby4gkxdjs130.jpg "/>

5 , adding a button event:  

button is added, you need to receive the button's event, the following is to introduce the implementationEventthe response. ATLto beCOMobject thatIdispatchthe interface provides two template classes:IDispEventImpl<> andIDispEventSimpleImpl<>, selectIDispEventSimpleImpl<> because it does not require additional type library information, fromIDispEventSimpleImpla <> inherits a class:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/79/wKiom1PoYXLC5_HLAABXp9bFKiw718.jpg "title=" 12.jpg "alt=" Wkiom1poyxlc5_hlaabxp9bfkiw718.jpg "/>

you can then add the event map macro to receive the event. Begin_sink_map (cpdfreader) end_sink_map ()
the next thing we do is to add a click event for the button. The first is to use the _atl_sink_info structure to describe the callback parameter information, must be declared as an external variable , We pre-defined some parameters for the event description, as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/79/wKiom1PoYYCB8X41AAGSBoTo9IA457.jpg "title=" 13.jpg "alt=" Wkiom1poyycb8x41aagsboto9ia457.jpg "/>

callback function for declaring button click events :

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/7A/wKioL1PoYqjxtwpLAAA8iaC3n1Q369.jpg "title=" 14.jpg "alt=" Wkiol1poyqjxtwplaaa8iac3n1q369.jpg "/>

Then add the event map at the event map:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/7A/wKioL1PoYrDBAW-8AAE0uqgYFNo674.jpg "title=" 15.jpg "alt=" Wkiol1poyrdbaw-8aae0uqgyfno674.jpg "/>

compile and run. Click the button, no popup dialog box. Well, that's right, we still have one more step to do. Increase the dispeventadvise of the event class . Add the following code to the Join function:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/45/7A/wKioL1PoYrnRFCLIAAA4wi5oi7E503.jpg "title=" 17.jpg "alt=" Wkiol1poyrnrfcliaaa4wi5oi7e503.jpg "/>

Do not forget to release the event response in a disconnected location:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/45/7A/wKioL1PoYsDxRxAJAACSWcSXKxk127.jpg "title=" 18.jpg "alt=" Wkiol1poysdxrxajaacswcsxkxk127.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/45/7A/wKioL1PoYsuQ88m-AACOgDMobJU039.jpg "title=" 19.jpg "alt=" Wkiol1poysuq88m-aacogdmobju039.jpg "/>

All right, a plug-in is done, pro. , hurry to try it, do not understand the place, please hurry up here official website .  


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.