Outlook, Word COM Addin Delphi Delphi Delphi Delphi Delphi! (Sorting into the exploration)

zhaozj2021-02-16  46

In the toolbar or menu bar resources in the Word2000, Access 2000, Excel2000, PowerPoint2000, etc. in Office2000, see some other software joined for new custom toolbar buttons or menu bars, there will be different when clicked them. The response occurs. Here we don't have to use VB / VBA without VC6, but use Delphi (5, 6, 7) to develop the Office2000 internal COM plug-in with this effect. In Office2000, whether it is Word2000, Access2000, Excel120000, PowerPoint2000 or Outlook2000, etc., their COM plug-in programming methods and steps are extremely similar (in addition to the key value of the registry and importing the corresponding type of library), specific programming differences I will indicate in the program. COM add a lower internal Office2000 _IDTExtensibility2 must implement a distributed interfaces, interfaces are defined in the distribution _IDTExtensibility2 MSADDin Designer type library (MSADDNDR.dll / MSADDNDR.tlb) usually located at / Program Files / Common Files / Designer under. The following five interfaces must be implemented in the interface (generally need to write onConnection and ONDISCONNECTION in the ONCONNECTION and the ONDISCONNECTION, and the Delphi automatically generates frameworks), as follows: 1. ONCONNECTION: Load insert to memory processing (can be automated in the program Automatic loading plug-in). 2. OnDisconnection: Processs when the plugin is loaded from the memory. 3. Onaddinsupdate: The COM plug-in is handled. 4. OnStartUpComplete: Processing when the plugin is just loaded when the application starts. 5. Onbeginshutdown: The plugin is complete when the plugin is complete when the application is turned off. Only when registering the internal COM plug-in that the appropriate application is properly registered, you will be loaded by its application, you will see the registered COM plug-in in the tool of Outlook or Word. You need to create the following key value in the registry: HKEY_CURRENT_USER / SOFTWARE / Microsoft / Office / / address / where theofficeApp represents the corresponding program name, such as: Word, Outlook, etc., Progid means the only internal COM plugin The character string representation of the identifier, such as: Project1.myoutLookAddin, etc. Under the PROGID key value, the following key value is mainly created: 1. FriendlyName: String type, the name of the plugin, will be seen in the COM Load dialog of the corresponding program. 2. Loadbehavior: Double byte type, determine the plugin will be loaded in any form. When its value is 0x03, it is automatically loaded for the application (usually using this value), and when its value is 0x08, the load is controlled to activate the load.

Below, I will give you a detailed explanation process:

1. New Active Library, save to Project1, this is the front section of Progid, newcom object, fill in the nameOKAddin in Class Name, which will be the rear section of the ProgID, click the list button behind the imported interface. Click the Add library button in the dialog box, select the MsadDr.dll file under the "Program Files / Common Files / Designer" directory. Then find the _idTextensibility2 interface inside MsadDndr.dll in the list. OK. Now the com address section has been completed, now add a CommandBar and two buttons in Outlook, and let the button respond to user-defined event 3, create a new unit, mainly create a new TcommandbarButton's Oleserver class to connect to CommandButton and respond to events Remember, must reference the Office2000, Outlook2000 unit. Code: The following definitions section TCommandBarButtonClick = procedure (const Ctrl: OleVariant; var CancelDefault: OleVariant) of Object; TCommandBarButton = class (TOleServer) private FIntf: CommandBarButton; FOnClick: TCommandBarButtonClick; function GetDefaultInterface: CommandBarButton; procedure SetOnClick (const Value: TCommandBarButtonClick) ; protected procedure InitServerData; override; procedure InvokeEvent (DispID: TDispID; var Params: TVariantArray); override; public constructor Create (AOwner: TComponent); override; destructor Destroy; override; procedure Connect; override; procedure ConnectTo (svrIntf: CommandBarButton) Procedure Disconnect; Override; Property DefaultInterface: CommandbarButton ReadDefaultInterface; Published Property OnClick: TcommandbarButtonClick read fonclick write setonclick; end; // Implementation section

{Tcommandbarbutton}

Procedure tcommandbarbutton.connect; varpunk: iUnknown; beginif fintf = nil dam: = GetServer; ConnecTevents (punk); fintf: = punk as commandbutton; end;

Procedure TcommandbarButton.ConnectTo (SVRINTF: Commandbarbutton); Begin Disconnect; FINTF: = SVRINTF; ConnecTevents (FINTF);

Constructor TcommandbarButton.create (Aowner: Tcomponent); Begin Inherited; End; Destructor TcommandbarButton.destroy;

Procedure TcommandbarButton.disconnect; Begin IF FINTF <> NIL THEN BEGIN DISCONNECTEVENTS (FINTF); FINTF: = NIL; END;

function TCommandBarButton.GetDefaultInterface: CommandBarButton; begin if FIntf = nil then Connect; Assert (FIntf <> nil, 'DefaultInterface is NULL Component is not connected to Server You must call..' 'Connect' 'or' 'ConnectTo' 'before this Operation '); result: = FINTF; END;

procedure TCommandBarButton.InitServerData; const CServerData: TServerData = (ClassID: '{C45BDF5C-8430-4e26-97EF-B3624198366D}'; // just three GUID IntfIID: '{A30AF5AC-D1FD-486a-8C7E-F71416EAFC4B}'; EventIID : {24BDE880-D3DB-4777-A5D4-AD24E1E3FCBD} '; licenseKey: NIL; Version: 500); Begin ServerData: = @cServerData; END;

procedure TCommandBarButton.InvokeEvent (DispID: TDispID; var Params: TVariantArray); begin case DispID of -1: Exit; // DISPID_UNKNOWN 1: if Assigned (FOnClick) then FOnClick (Params [0], Params [1]); end; {Case Dispid} END;

Procedure TcommandbarButton.SetonClick (const value: tcommandbarbutton); begin fonclick: = value;

4, proceed TMyOutlookAddIn class defines which class Additions private FCommandBarButton: TCommandBarButton; FCommandBarButton2: TCommandBarButton; procedure FClick (const Ctrl: OleVariant; var CancelDefault: OleVariant); procedure F2Click (const Ctrl: OleVariant; var CancelDefault: OleVariant);

In writing the code below OnConnection procedure TMyOutLookAddIn.OnConnection (const Application: IDispatch; ConnectMode: ext_ConnectMode; const AddInInst: IDispatch; var custom: PSafeArray); // read and copied to a clipboard Bitmap procedure CopyBitMapToClipBoard (strFile: string); var aBitMap: TBitmap; begin with TClipboard.Create do begin try aBitMap: = TBitmap.Create; aBitMap.LoadFromFile (strFile); Assign (aBitMap); finally aBitMap.Free; Free; end; end; end; var App: OutLookApplication; / / Word Addin implementation, definition: WordApp: WordApplication Acommandbar: commandbar; Abutton, Abutton2: _CommandbarButton; Begin

App: = OutLookApplication (Application); aCommandBar: = App.ActiveExplorer.CommandBars.Add ( 'NewButtonBar', msoBarTop, False, True); // button bar // word addin realize the difference // App: = WordApplication (Application); // acommandbar: = app.commandbars.add ('syni', msobartop, false, true); // Button column

// first button aButton: = aCommandBar.Controls.Add (msoControlButton, EmptyParam, EmptyParam, EmptyParam, True) as _CommandBarButton; aButton.Set_Style (msoButtonIconAndCaption); aButton.Set_Caption ( 'SCP Manager'); CopyBitMapToClipBoard (YourBmpFile); // These two sentences are set to the button to set an external icon, Abutton.Pasteface; // You have to add a Bitmap resource Bitmap size 16 * 16 Abutton.Set_tag ('manger'); fcommandbarbutton: = tcommandbarbutton.create (NIL ); Fcommandbarbutton.connectto (abutton); // Button association fcommandbarbutton.onclick: = fclick; // Response event assignment

// Second button aButton2: = aCommandBar.Controls.Add (msoControlButton, EmptyParam, EmptyParam, EmptyParam, True) as _CommandBarButton; aButton2.Set_Style (msoButtonIconAndCaption); aButton2.Set_Caption ( 'SCP History'); CopyBitMapToClipBoard (YourBmpFile2); // These two sentences are set to the button to set an external icon, Abutton2.Pasteface; // Abutton2.set_tag ('history'); // must be with other Button Different fcommandbutton2: = tcommandbutton.create (nil); fcommandbarbutton2.connectto (Abutton2); fcommandbarbutton2.onclick: = f2click; // Response event 2acommandBar.Set_Visible (TRUE);

In the code below OnDisconnection write procedure TMyOutLookAddIn.OnDisconnection (RemoveMode: ext_DisconnectMode; var custom: PSafeArray); begin FCommandBarButton.Disconnect; FCommandBarButton.Free; FCommandBarButton2.Disconnect; FCommandBarButton2.Free; end;

// Write the Click event (pop up a Dialog) Procedure TmyoutLookAddin.fclick (const ctrl: olevariant; var canceldefault: olevariant); begin showMessage ('Activating Manager Button Click Event'); end; // Write Click events (execute a program) Procedure TMYOUOKADDIN.F2Click (const ctrl: olevariant; var caledefault: olevariant); Begin Shellexecute (NIL, 'Open', 'YOUREXEPRAM', NIL, NIL, SW_SHOW);

5, final compilation registration. You have to open the regedit, write the registry as mentioned earlier. You can guide it, and you can merge it directly when you use other machines.

6. Run Outlook2000 or 2003, you can see the effect.

Reference: COM Add-INS: Building a COM Add-in for Outlook 2000 - (MSDN, Thomas Rizzo) Office2000 Co-CoM addin with Delphi (cwxiao888)

Friends who need code, contact me, leyi.163 @ 163.com

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

New Post(0)