选择Delphi得project/import type library , 选择 add , 查找Office目录下面得MSWORD9.OLB(Word2000)
文件,然后 create unit,可以建立Office_TLB, Word_TLB单元,并请大家仔细研究该单元得所有接口、类方法
、属性定义,肯定可以实现得
下面是我刚刚写的测试代码,没有高定的是如何将函数附加到按键的事件上面去,各位再研究一下把
我现在得出差了,回来再看看大家讨论得如何。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Office_TLB, Word_TLB, OleServer;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
appWord: _Application ;
cBar : CommandBar ;
cBarCtl : CommandBarControl ;
cBarBtnCustom: CommandBarButton ;
implementation
{$R *.dfm}
function actionTest:integer;
begin
ShowMessage('DragonPC Word Build-in Toolbar Test Program') ;
result := 0 ;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
appWord := CoWordApplication.Create() ;
cBar := appWord.CommandBars.Add('DragonPC Toolbar', msoBarFloating, EmptyParam, EmptyParam) ;
cBar.Set_Visible(true);
cBarCtl := cBar.Controls.Add(msoControlButton, EmptyParam, EmptyParam, EmptyParam, EmptyParam) ;
// you can use msoControlComboBox or other to add some other visual control.
// Style = msoButtonCaption
cBarCtl.Set_Caption('Button');
cBarCtl.Set_TooltipText('DragonPC Word Build-in Custom Button Test.');
cBarCtl.Set_OnAction('=actionTest;') ;
cBarCtl.Set_Visible(true) ;
appWord.Visible := true ;
end;
end.