关于WORD插件的问题,急~~急~~~急~~~~!!!(80分)

  • 主题发起人 主题发起人 wjj0310
  • 开始时间 开始时间
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.
 
在线等啊~!!!!
 
procedure TAddIn.OnConnection(const Application: IDispatch;
ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch;
var custom: PSafeArray);
var
App : WordApplication;
aCommandBar : CommandBar;
begin

App := WordApplication(Application);
aCommandBar := App.CommandBars.Add('SYNI', msoBarTop, False, True);
//button栏
......
 
to yuzk2005:
还是不行列。。你的意思是什么?
 
如果你生成的是com-addin加载项, 需要在注册表中注册, 然后在word菜单->工具->com加载项 进行加载(具体操作可从网上搜一搜)
 
我试下先~!!~好象找不到com加载项 这一栏哦。。。
 
还是不行。大虾们帮帮忙,这么多富翁不是吗?。com加载项里头加载不了。

郁闷~!!!!。[:(]
 
接受答案了.
 
后退
顶部