W
wjj0310
Unregistered / Unconfirmed
GUEST, unregistred user!
大虾们发点时间帮我看看,到底是哪里错了。。。怎么word中显示不出我的插件呢??[]
代码如下:
nit AddInMain;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AddInMain_TLB, StdVcl,Windows, Messages, SysUtils,
Classes, Graphics, Controls, Forms,AddinDesignerObjects_TLB,cmdbarbtn,Word_TLB, Office_TLB,variants,BtnSvr;
type
TAddIn = class(TAutoObject, IAddIn, IDTExtensibility2)
private
FWordApp : TWordApplication;
DICommandBar : CommandBar;
EmptyParam:OleVariant;
BtnIntf:CommandBarControl;
FCommandBarButton : TCommandBarButton;
HCommandBarButton : TCommandBarButton;
protected
procedure OnConnection(const Application: IDispatch;ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch;var custom: PSafeArray);
safecall;
procedure OnDisconnection(RemoveMode: ext_DisconnectMode;var custom: PSafeArray);
safecall;
procedure OnAddInsUpdate(var custom: PSafeArray);safecall;
procedure OnStartupComplete(var custom: PSafeArray);
safecall;
procedure Onbegin
Shutdown(var custom: PSafeArray);
safecall;
public
procedure encClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
procedure MenuClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
procedure dscClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
property WordApp : TWordApplication read FWordApp;
end;
implementation
uses ComServ;
{ TAddIn }
procedure TAddIn.MenuClick(const Ctrl: OleVariant;
var CancelDefault: OleVariant);
begin
end;
procedure TAddIn.OnAddInsUpdate(var custom: PSafeArray);
begin
end;
procedure TAddIn.Onbegin
Shutdown(var custom: PSafeArray);
begin
end;
procedure TAddIn.OnConnection(const Application: IDispatch;
ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch;
var custom: PSafeArray);
var
WA : Word_TLB._Application;
acommandbar:commandbar;
aButton:Office_TLB._CommandBarButton;
bButton:Office_TLB._CommandBarButton;
emptyparam:OleVariant;
begin
FWordApp := TWordApplication.Create(nil);
WA := Application as Word_TLB._Application;
FWordApp.ConnectTo(WA);
aCommandBar:=WordApp.CommandBars.Add('外加控件',msoBarTop,false,true);
aButton := aCommandBar.Controls.Add(msoControlButton, emptyparam, emptyparam,emptyparam, true) as _CommandBarButton;
bButton := aCommandBar.Controls.Add(msoControlButton, emptyparam, emptyparam,emptyparam, true) as _CommandBarButton;
aButton.Set_Style(msoButtonIconAndCaption);
bButton.Set_Style(msoButtonIconAndCaption);
aButton.Set_Caption('button1');
bButton.Set_Caption('button2');
aButton.Set_Tag('test1');
bButton.Set_Tag('test2');
aButton.set_Visible(True);
bButton.set_Visible(True);
FCommandBarButton := TCommandBarButton.Create(nil);
HCommandBarButton := TCommandBarButton.Create(nil);
FCommandBarButton.ConnectTo(aButton);
HCommandBarButton.ConnectTo(bButton);
FCommandBarButton.OnClick := encClick;
HCommandBarButton.OnClick := dscClick;
aCommandBar.Set_Visible(True);
end;
procedure TAddIn.OnDisconnection(RemoveMode: ext_DisconnectMode;
var custom: PSafeArray);
begin
WordApp.Free;
end;
procedure TAddIn.OnStartupComplete(var custom: PSafeArray);
begin
end;
procedure TAddIn.encClick(const Ctrl: OleVariant;
var CancelDefault: OleVariant);
var
I:integer;
begin
DICommandBar := nil;
for i := 1 to WordApp.CommandBars.Countdo
if (WordApp.CommandBars.Item.Name ='button1') then
DICommandBar := WordApp.CommandBars.Item;
// 确定是否已经注册了命令条
if (not Assigned(DICommandBar)) then
begin
DICommandBar:=FWordApp.CommandBars.Add('button1',EmptyParam,EmptyParam,EmptyParam);
DICommandBar.Set_Protection(msoBarNoCustomize);
end;
if (DICommandBar.Controls.Count > 0) then
BtnIntf := DICommandBar.Controls.Item[1]
else
BtnIntf := DICommandBar.Controls.Add(msoControlButton,EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
procedure TAddIn.dscClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
var
I:integer;
begin
DICommandBar := nil;
for i := 1 to WordApp.CommandBars.Countdo
if (WordApp.CommandBars.Item.Name ='button2') then
DICommandBar := WordApp.CommandBars.Item;
// 确定是否已经注册了命令条
if (not Assigned(DICommandBar)) then
begin
DICommandBar:=FWordApp.CommandBars.Add('button2',EmptyParam,EmptyParam,EmptyParam);
DICommandBar.Set_Protection(msoBarNoCustomize);
end;
if (DICommandBar.Controls.Count > 0) then
BtnIntf := DICommandBar.Controls.Item[1]
else
BtnIntf := DICommandBar.Controls.Add(msoControlButton,EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
initialization
TAutoObjectFactory.Create(ComServer, TAddIn, Class_AddIn,ciMultiInstance, tmApartment);
end.
代码如下:
nit AddInMain;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, AddInMain_TLB, StdVcl,Windows, Messages, SysUtils,
Classes, Graphics, Controls, Forms,AddinDesignerObjects_TLB,cmdbarbtn,Word_TLB, Office_TLB,variants,BtnSvr;
type
TAddIn = class(TAutoObject, IAddIn, IDTExtensibility2)
private
FWordApp : TWordApplication;
DICommandBar : CommandBar;
EmptyParam:OleVariant;
BtnIntf:CommandBarControl;
FCommandBarButton : TCommandBarButton;
HCommandBarButton : TCommandBarButton;
protected
procedure OnConnection(const Application: IDispatch;ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch;var custom: PSafeArray);
safecall;
procedure OnDisconnection(RemoveMode: ext_DisconnectMode;var custom: PSafeArray);
safecall;
procedure OnAddInsUpdate(var custom: PSafeArray);safecall;
procedure OnStartupComplete(var custom: PSafeArray);
safecall;
procedure Onbegin
Shutdown(var custom: PSafeArray);
safecall;
public
procedure encClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
procedure MenuClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
procedure dscClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
property WordApp : TWordApplication read FWordApp;
end;
implementation
uses ComServ;
{ TAddIn }
procedure TAddIn.MenuClick(const Ctrl: OleVariant;
var CancelDefault: OleVariant);
begin
end;
procedure TAddIn.OnAddInsUpdate(var custom: PSafeArray);
begin
end;
procedure TAddIn.Onbegin
Shutdown(var custom: PSafeArray);
begin
end;
procedure TAddIn.OnConnection(const Application: IDispatch;
ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch;
var custom: PSafeArray);
var
WA : Word_TLB._Application;
acommandbar:commandbar;
aButton:Office_TLB._CommandBarButton;
bButton:Office_TLB._CommandBarButton;
emptyparam:OleVariant;
begin
FWordApp := TWordApplication.Create(nil);
WA := Application as Word_TLB._Application;
FWordApp.ConnectTo(WA);
aCommandBar:=WordApp.CommandBars.Add('外加控件',msoBarTop,false,true);
aButton := aCommandBar.Controls.Add(msoControlButton, emptyparam, emptyparam,emptyparam, true) as _CommandBarButton;
bButton := aCommandBar.Controls.Add(msoControlButton, emptyparam, emptyparam,emptyparam, true) as _CommandBarButton;
aButton.Set_Style(msoButtonIconAndCaption);
bButton.Set_Style(msoButtonIconAndCaption);
aButton.Set_Caption('button1');
bButton.Set_Caption('button2');
aButton.Set_Tag('test1');
bButton.Set_Tag('test2');
aButton.set_Visible(True);
bButton.set_Visible(True);
FCommandBarButton := TCommandBarButton.Create(nil);
HCommandBarButton := TCommandBarButton.Create(nil);
FCommandBarButton.ConnectTo(aButton);
HCommandBarButton.ConnectTo(bButton);
FCommandBarButton.OnClick := encClick;
HCommandBarButton.OnClick := dscClick;
aCommandBar.Set_Visible(True);
end;
procedure TAddIn.OnDisconnection(RemoveMode: ext_DisconnectMode;
var custom: PSafeArray);
begin
WordApp.Free;
end;
procedure TAddIn.OnStartupComplete(var custom: PSafeArray);
begin
end;
procedure TAddIn.encClick(const Ctrl: OleVariant;
var CancelDefault: OleVariant);
var
I:integer;
begin
DICommandBar := nil;
for i := 1 to WordApp.CommandBars.Countdo
if (WordApp.CommandBars.Item.Name ='button1') then
DICommandBar := WordApp.CommandBars.Item;
// 确定是否已经注册了命令条
if (not Assigned(DICommandBar)) then
begin
DICommandBar:=FWordApp.CommandBars.Add('button1',EmptyParam,EmptyParam,EmptyParam);
DICommandBar.Set_Protection(msoBarNoCustomize);
end;
if (DICommandBar.Controls.Count > 0) then
BtnIntf := DICommandBar.Controls.Item[1]
else
BtnIntf := DICommandBar.Controls.Add(msoControlButton,EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
procedure TAddIn.dscClick(const Ctrl: OleVariant;var CancelDefault: OleVariant);
var
I:integer;
begin
DICommandBar := nil;
for i := 1 to WordApp.CommandBars.Countdo
if (WordApp.CommandBars.Item.Name ='button2') then
DICommandBar := WordApp.CommandBars.Item;
// 确定是否已经注册了命令条
if (not Assigned(DICommandBar)) then
begin
DICommandBar:=FWordApp.CommandBars.Add('button2',EmptyParam,EmptyParam,EmptyParam);
DICommandBar.Set_Protection(msoBarNoCustomize);
end;
if (DICommandBar.Controls.Count > 0) then
BtnIntf := DICommandBar.Controls.Item[1]
else
BtnIntf := DICommandBar.Controls.Add(msoControlButton,EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
initialization
TAutoObjectFactory.Create(ComServer, TAddIn, Class_AddIn,ciMultiInstance, tmApartment);
end.