当我使用下面的代码在delphi 7中编写tapi3时,我可以制作一个 拨打电话,但我无法发现任何事件。有没有人面对同样的事情 问题?
unit Unit10;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, TAPI3Lib_TLB, StdCtrls, ActiveX, ComObj, OleServer;
{
type
TTapiEventsSink = class( TObject, IConnectionPointContainer, I)
procedure TAPI1Event(ASender: TObject; TapiEvent: TOleEnum;
const pEvent: IDispatch);
end;
}
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
Edit2: TEdit;
Button4: TButton;
TAPI1: TTAPI;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure TAPI1Event(ASender: TObject; TapiEvent: TOleEnum;
const pEvent: IDispatch);
private
{ Private declarations }
public
{ Public declarations }
tapi3 : ITTAPI;
addr : ITAddress;
media : ITMediaSupport;
addrs : IEnumAddress;
term : ITTerminal;
terminalSupport : ITTerminalSupport;
basicall :ITBasicCallControl;
dir : TOleEnum;
streamControl : ITStreamControl;
enumStream : IEnumStream;
stream : ITStream;
mediatype : Integer;
direct : TERMINAL_DIRECTION;
lAddressType : Integer;
bHold : Boolean;
event : ITCallNotificationEvent;
tapievent : ITTAPIEventNotification;
unknown : IUnknown;
end;
const TAPI3_CALL_EVENTS =
TE_CALLMEDIA OR
TE_CALLNOTIFICATION OR
TE_CALLSTATE;
const
TAPIMEDIATYPE_AUDIO = $8;
TAPIMEDIATYPE_VEDIO = $8000;
TAPIMEDIATYPE_DATEMODEM = $10;
TAPIMEDIATYPE_G3FAX = $20;
LINEADDRESSTYPE_PHONENUMBER = $00000001;
EVENT_FILTER =
TE_TAPIOBJECT OR
TE_ADDRESS OR
TE_CALLNOTIFICATION OR
TE_CALLSTATE OR
TE_CALLMEDIA OR
TE_CALLHUB OR
TE_CALLINFOCHANGE OR
TE_PRIVATE OR
TE_REQUEST OR
TE_AGENT OR
TE_AGENTSESSION OR
TE_QOSEVENT OR
TE_AGENTHANDLER OR
TE_ACDGROUP OR
TE_QUEUE OR
TE_DIGITEVENT OR
TE_GENERATEEVENT;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
lwCeltFetched : Cardinal;
cookievar : Integer;
begin
bHold := false;
tapi1.Initialize;
tapi1.Connect;
{ Select an address }
// list address
addrs := tapi1.DefaultInterface.EnumerateAddresses;
//addrs := tapi3.EnumerateAddresses;
while ( S_OK = addrs.Next(1,addr,lwCeltFetched) ) do
begin
ComboBox1.Items.Add(addr.AddressName);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
basicall.Disconnect(DC_NORMAL);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
lwCeltFetched : Cardinal;
iRes : Integer;
i : Integer;
hr : Integer;
begin
{ Select an address }
addrs.Reset;
while ( S_OK = addrs.Next(1,addr,lwCeltFetched) ) do
begin
hr := addr.QueryInterface(IID_ITMediaSupport,media);
if ( true = media.QueryMediaType(TAPIMEDIATYPE_AUDIO) ) then
break;
end;
tapi1.EventFilter := EVENT_FILTER;
tapi1.RegisterCallNotifications(addr,true,false,TAPIMEDIATYPE_AUDIO,1);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
phonenum : array [0..30] of char;
begin
lAddressType := LINEADDRESSTYPE_PHONENUMBER;
StrPCopy( phonenum, Edit1.Text );
basicall :=
addr.CreateCall(phonenum,lAddressType,TAPIMEDIATYPE_AUDIO);
basicall.Connect(false);
end;
procedure TForm1.TAPI1Event(ASender: TObject; TapiEvent: TOleEnum;
const pEvent: IDispatch);
var
callinfo : ITCallInfo;
event : ITCallNotificationEvent;
begin
Memo1.Lines.Add('hi');
Memo1.Refresh;
case TapiEvent of
TE_CALLNOTIFICATION :
begin
Memo1.Lines.Add('call notification');
end;
end;
end;
当有人通过调制解调器给我打电话时,我需要获得来电显示。
谢谢。