Programming implementation of internal COM plug-ins in Access2000

zhaozj2021-02-08  244

Programming implementation of internal COM plug-ins in Access2000

Author: Xu Jing Zhou

Download Sample Code (http://www.vckbase.com/document/viewdoc.asp?id=826)

Introduction

Here, we still use the ATL in the VC6 to implement the internal COM plug-in under Access 2000, as for the basic principles and detailed implementation methods and steps, you can see the front of my article , here, here It is only necessary to explain the differences between it and other Office2000 (eg Word2000, Excel2000, PowerPoint2000, Outlook2000) implementation, articles and sample code can be found in http://www.vckbase.com website. Below is the rendering of the ACCESS2000 COM plug-in sample code running:

Implementation

Open VC6.0, select the ATL COM AppWizard in the new project, enter AccessAddin in the right project name, click the Finish button to complete the project creation. Next, select the menu INSERT-> New ATL OBJEC item, select the corresponding Objects corresponding to the right of Objects corresponding to the appropriate Objects in the pop-up, click Next, enter acceaddin in the pop-up dialog box, point OK to complete Insert an ATL object.

Then by importing the model library, the right click on the CACCEADDIN class in ClassView in the CACCEADDIN class in ClassView, select the Implement Interface item in the pop-up. Click Add Typelib in the Pop-up Implementation Interface dialog box. In the pop-up Browse Type Libraries dialog box, scroll down the Microsoft Add-in Designer (1.0) sub-item, point OK button. Select the _idtextensibility2 interface in the pop-up list dialog, point the OK button to complete the import. The system will automatically generate the five required number of interfaces mentioned above.

Let's take a look at the difference between them.

The first point: registration type information is different (* .RGS), below the contents of the file acceaddin.rgs, add the code:

HKCU

{

Software

{

Microsoft

{

Office

{

ACCESS

{

Addins

{

'AccessAddin.acceddin'

{

Val FriendlyName = S 'Access2000 Plugin'

Val description = s 'uses ATL development Access2000 internal plugin'

Val loadbehavior = d '00000003'

Val CommandLinesAfe = D '00000000'

}

}

}

}

}

}

}

Second point: The import library of the type of type in STDAFX.H in the file will be different, and the following code can be added to STDAFX.H.

#pragma Warning (Disable: 4146) // Temporarily Shield Compile 4146 Warning Information

// Import Access 2000 Required Type Library ADO, DAO, VBE, OFFICE and Access libraries (specific paths can be set according to actual conditions, Jingzhou XU)

#import "D: // program files // common files // system // ado // msado21.tlb" no_namespace /

Rename ("EOF", "AdoEOF") # import "D: // Program files // Common files // microsoft shared // DAO // DAO360.DLL" RENAME ("EOF", "ENDOFFILE") /

Rename ("BOF", "Begoffile")

#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 / msacc9.olb" named_guids, rename_namespace ("msaccess")

Using namespace msaccess;

#pragma Warning (Default: 4146) // Restore compilation 4146 Warning Information

Third point: There is no ActiveExplorer object in Access 2000, so you don't have to go to CommistBars directly like Outlook2000, you can use the CommandBars object from _application. The modification section is shown in the following source code:

// Treatment when installing the plugin, Jingzhou XU

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

{

CComptr spcmdbars;

// Access 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);

// Add a tool bar and its previous bitmap button

CCOMVARIANT VNAME ("New Access 200 Tool Bar Plugin");

CComptr spnewcmdbar;

// New tool strip position

CComvariant VPOS (1);

Ccomvariant vTemp (variant_true); // temporary

CCOMVARIANT VEMPTY (DISP_E_PARAMNOTFOUND, VT_ERROR);

// Add a toolbar with the add method and let spnewcmdbar points to it.

Spnewcmdbar = spcmdbars-> add (vName, VPOS, Vempty, VTEMP);

// Get the CommandBarControls of the new toolbar so that the button is added there

CComptrols> spbarcontrols;

Spbarcontrols = spbarcontrols = spnewcmdbar-> getControls (); atlassert (spbarcontrols);

// msoControlType :: msocontrolbutton = 1

Ccomvariant vtoolbartype (1);

// Display Toolbar

CCOMVARIANT VSHOW (VARIANT_TRUE);

CComptrol> SPNewBar;

// Add the first button with the Add method in CommandBarControls and let spnewbar points to it

Spnewbar = spbarcontrols-> add (vtoolbartype, vempty, vempty, vempty, vshow);

Atlassert (SPNEWBAR);

/ / Specify the _commandbarbutton interface for each button, can specify the display style of the button, etc.

CCOMQIPTR spcmdbutton (spnewbar);

Atlassert (spcmdbutton);

/ / Set the bitmap button style, the bitmap is 32x32 size, put it in the shear board, and paste it on the specified button with pasteface ()

Hbitmap HBMP = (Hbitmap) :: loadimage (_Module.getResourceInstance (),

MakeintResource (idb_bitmap), image_bitmap, 0,0, lr_loadmap3dcolors;

:: OpenClipboard (NULL);

:: EmptyClipboard ();

:: setClipboardData (cf_bitmap, (handle) HBMP;

:: closeclipboard ();

:: DeleteObject (HBMP);

// Paste the front settings display style

Spcmdbutton-> PutStyle (Office :: msobuttoniconandcaption);

HR = spcmdbutton-> pasteface ();

IF (Failed (HR))

Return HR;

SpcmdButton-> Putvisible (Variant_True);

SpcmdButton-> Putcaption (OLESTR ("button 1");

Spcmdbutton-> Putenabled (Variant_True);

SpcmdButton-> Puttooltiptext (OLESTR ("button 1 prompt information");

Spcmdbutton-> Puttag (OLESTR ("button 1 flag information"));

/ / Show new toolbar

Spnewcmdbar-> putvisible (variant_true);

m_spButton = spcmdbutton;

/ / Activate the event connection point of the new toolbar button

m_spapp = spApp;

HR = CommandButton1Events :: DispeventadVise ((iDispatch *) m_spButton);

IF (Failed (HR))

Return HR;

:: EmptyClipboard ();

Return S_OK;

}

The difference is mainly above three points, as for other parts, such as the toolbar button CommandBarbutton distribution interface response event, open or disconnect the connection method, etc. If you are interested in friends, please refer to several of the following references to implement articles about the internal COM plug-ins of Office2000, and then see this article and sample source code will be easy. references:

Programming Implementation of Internal COM Plugins under Office2000 - Xu Jinghou

Programming Implementation of internal COM plugins in Word2000 / XP - Xu Jingzhou

Implementation of Excel2000 / XP and PowerPoint2000 / XP - Xu Jingzhou

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

Contact information:

Editor Email: jingzhou_xu@163.com

Future Studio (Future Studio)

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

New Post(0)