我想在 Outlook 关闭时提示用户。我已经在我的应用程序中使用了兑换。我不想使用Delphi提供的TOutlookApplication Class。
请帮助我在德尔福上实现Outlook Onclose/OnQuit事件。
当我使用 TOutlookApplication for OnQuit 事件的对象时,如果我的应用程序繁忙,例如:执行一个需要 1 分钟以上的 SQL 状态,我的 Outlook 就会挂起。最终,我需要避免这种挂起。
请帮帮我。
谢谢和问候,维杰什·奈尔
前段时间我实现了 Outlook 事件侦听器。我使用导入Outlook_tlb库来处理 Outlook。您可以通过IConnectionPoint
界面接收Outlook通知。事件侦听器类必须实现IDispatch
接口(至少Invoke
方法)。所以,有示例代码:将 TOutlookEventListener 声明为:
TOutlookEventListener = class(TInterfacedObject, IDispatch)
strict private
FConnectionPoint : IConnectionPoint;
FCookie : integer;
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
public
constructor Create();
end;
在构造函数代码中,您必须获取OutlookApplication的实例,找到连接点并将自身注册为事件侦听器:
constructor TOutlookEventListener.Create();
var cpc : IConnectionPointContainer;
ol : IDispatch;
begin
inherited Create();
ol := GetActiveOleObject('Outlook.Application');
cpc := ol as IConnectionPointContainer;
cpc.FindConnectionPoint(DIID_ApplicationEvents, FConnectionPoint);
FConnectionPoint.Advise(self, FCookie);
end;
使用Invoke
方法可以筛选事件。 Quit
事件具有 DispID = 61477
function TOutlookEventListener.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer): HResult;
begin
result := S_OK;
case DispId of
61442 : ; // ItemSend(const Item: IDispatch; var Cancel: WordBool);
61443 : ; // newMailEventAction();
61444 : ; // Reminder(const Item: IDispatch);
61445 : ; // OptionsPagesAdd(const Pages: PropertyPages);
61446 : ; // Startup;
61447 : begin
FConnectionPoint.Unadvise(FCookie);
FConnectionPoint := nil;
form1.OutlookClosed(self);
end
else
result := E_INVALIDARG;
end;
end;
其他方法必须返回E_NOTIMPL结果。
在 OnCreate 事件处理程序窗体中,创建 TOutlookEventListener 的实例(假设 Outlook 已经在运行)。我还使用 TForm1.OutlookClosed(发件人:TObject) 事件来显示通知消息。
阅读有关 Outlook 事件的文章:http://www.codeproject.com/Articles/4230/Implementing-Outlook-2002-XP-Event-Sinks-in-MFC-C