Programming implementation of internal COM plug-ins in Word2000XP

zhaozj2021-02-08  201

Programming implementation of internal COM plug-ins in Word2000 / XP

Compilation: Xu Jingzhou

Download sample source code (http://www.vchelp.net/itbookreview/view_paper.asp?paper_id=734)

Introduction

Implementation method for internal COM plug-in under office2000 / XP and the front of my article The implementation method of the internal COM plug-in under Outlook2000 is basically the same, here, I think No need to repeat the content you have already told in the previous article, you will only focus on the different points of the realization, interested friends can see the previous article, and then watch this article will be more than half-time . The effect chart after the Word internal COM plug-in sample source code is shown below:

Implementation

Below, let's take a look at what the implementation of them (Word2000 VS Outlook2000 internal COM plug-in) is different? You can build an ATL project first, namely Wordaddin, insert a simple object, name iWord2000Addin, other steps to see the content described in front of the article introduced in the article. Here, in addition to the source code described below requires a change, the source code content of other parts is basically the same as the sample source code in the previous article, generally does not need to be changed (unless you have other special needs).

First point: The import part source code of the type in Stdafx.h in the file will be different, and the source code in the source file can be replaced with the following portion.

// Import project required Office2k and Word2K type library (path can be set according to the installation path), Jingzhou Xu

/ * Office XP is imported as follows: * /

// # Import "C: / Program files // Common files // microsoft shared // office10 // mso.dll" rename_namespace ("office")

// using namespace office;

// # import "D: // Program files // common files // microsoft shared // vba // vba6 // vbe6ext.olb" rename_namespace ("vbe6")

// using namespace VBE6;

// # Import "D: / proGram files / microsoft office / office10 / msword.olb" Rename ("EXITWINDOWS", "EXITWINDOWSEX"), NAMED_GUIDS, RENAME_NAMESPACE ("Msword")

// using namespace msword;

/ * Office 2000 Introduction to use * /

#import "E: // Program files // microsoft office // office // mso9.dll" Rename_NameSpace ("Office")

Using namespace office;

#import "D: // Program files // Common files // microsoft shared // vba // vba6 // vbe6ext.olb" Rename_Namespace ("VBE6")

Using namespace VBE6;

#import "E: // Program Files // Microsoft Office // Office // MSWORD9.OLB" Rename ("EXITWINDOWS", "EXITWINDOWSEX"), named_guids, rename_namespace ("mword") Using Namespace Msword;

Second: Registration Type Information Different (* .RGS), such as the second half of the content in the file word2000addin.RGS as follows:

HKCU

{

Software

{

Microsoft

{

Office

{

Word

{

Addins

{

'WordDin.Word2000Addin'

{

Val friendlyname = s 'Word2000 Addin'

Val description = s 'Word2000 Addin'

Val loadbehavior = d '00000003'

Val CommandLinesAfe = D '00000001'

}

}

}

}

}

}

}

Third point: There is no ActiveExplorer object in Word2000 / XP, so you can not pass it directly, you can use the CommandBars object from _application. The modification section is shown in the following source code:

// Treatment when installing the plugin

StdMethod (iDispatch * Application, EXT_CONNECTMODE CONNECTMODE, IDISPATCH * AddInSt, SafeArray * * Custom)

{

CComptr spcmdbars;

// Word application interface _application

CCOMQIPTR spApp (application);

Atlassert (SPAPP);

/ / Get the CommandBars interface

HRESULT HR = SPAPP-> Get_Commandbars (& spcmdbars);

IF (Failed (HR))

Return HR;

Atlassert (spcmdbars);

. . . . . .

. . . . . .

}

Ok, the different points of the internal COM plug-in implementation under Word2000 / XP and Outlook2000 are mainly these, and the detailed code of the specific implementation can be found in the two articles, which has detailed notes.

Finally, I want to add a little more, because the internal COM plug-in interface (especially the IDTEXTENSILITY2 interface) is not supported, the above programs are not applicable in Word97. In order to be used under Word97, we can use another method: both VBA ATL plugins. Since there is no IDTEXTENSIBILITY2 interface support, you cannot use onConnection () and the OndisConnection interface to implement the operation in loading plug-in and unloading the plug-in. We can create two number of interfaces in the project, namely: init (), and uninit (), as the two loaded, uninstall the number of loads mentioned above, can be added to init () Insert the toolbar button section, the code is approximately the same as the examples of this article, and uninit is implemented in Uninit (). You can then build a Word Template (* .dot), inserting VBA to implement the method of creation and loading, unloading components, such as the VBA source code: DIM O AS Application

DIM OBJ AS Object

SUB AutoExec ()

Set obj = creteObject ("word97addin.addin")

Set o = thisdocument.Application

Obj.init O

End Sub

SUB AutoExit ()

Set o = thisdocument.Application

Obj.uninit O

Set obj = Nothing

Set o = Nothing

End Sub

Since these are not the focus of this article (the focus is to implement the internal COM plug-in in Word2000 / XP), so I don't have to discuss it in detail, interested readers can refer to other related materials.

references:

Programming Implementation of Internal COM Plugins under Office2000 - Xu Jinghou (Translator)

Writing an MS Word Addin - Amit Dey

ATL Development Guide (Second Edition) - Tom Armstrong & Ron Patton

Contact information:

Email: jingzhou_xu@163.com

Future Studio (Future Studio)

转载请注明原文地址:https://www.9cbs.com/read-2172.html

New Post(0)