DELPHI 6 的DEMO中有一个控制WORD的例子(在 delphi6/demos/activex/oleaotu/word8),我对这个例子做了一些修改,即增加了一个 ONSAVEDOCUMENT的事件,用来截获WORD中保存文件的消息。WORD中保存文件时,发送一个消息,这个消息的值为8。主要是修改这一段语句:
function TWordEventSink.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HRESULT;
begin
case DispID of
2 : if Assigned(FOnQuit) then
FOnQuit(FOwner);
3 : begin
if Assigned(FOnDocumentChange) then
FOnDocumentChange(FOwner);
InterfaceDisconnect(FDocDispatch,FDocDispIntfIID,FDocConnection);
try
FDocDispatch := _Application(FAppDispatch).ActiveDocument;
InterfaceConnect(FDocDispatch,FDocDispIntfIID,Self,FDocConnection);
except;
end;
end;
4 : if Assigned(FOnNewDocument) then
FOnNewDocument(FOwner);
5 : if Assigned(FOnOpenDocument) then
FOnOpenDocument(FOwner);
6 : if Assigned(FOnCloseDocument) then
FOnCloseDocument(FOwner);
8 : if Assigned(FOnSaveDocument) then //这个是我自己增加的
FOnSaveDocument(FOwner);
end;
Result := S_OK;
end;
呵呵,进了一步,高兴啊!