110,538
社区成员
发帖
与我相关
我的任务
分享
#ifndef _USBDLL_H_
#define _USBDLL_H_
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the USBDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// USBDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef USBDLL_EXPORTS
#define USBDLL_API __declspec(dllexport)
#else
#define USBDLL_API __declspec(dllimport)
#endif
#include <wtypes.h>
#include <initguid.h>
#define RECORD_LOCAL 0
#define RECORD_TALK 1
#define RECORD_LY 2
// the following functions' definition and macros' definition are the APIs for USB protocol
//----from Phone to PC--------------------------
/*
//设备连接时发此消息(指USB线与PC和终端电话都连接好).
//参数wParam:(BYTE)序号; lParam: 0L.
*/
#define WM_DEVICECONNECT WM_USER+701
/*
//设备断开时发此消息(指USB线与PC或终端电话的任一方断开时发此消息).
//参数wParam:(BYTE)0L--全部断开; lParam: 0L.
// 1L--断开一台话机; lParam: (BYTE)序号
*/
#define WM_DEVICEDISCONNECT WM_USER+702
/*
//呼叫建立,即摘机时发送此消息.
//参数wParam:(BYTE)序号; lParam: 0L.
*/
#define WM_OFFHOOK WM_USER+703
/*
//呼叫断开,即挂机时发送此消息.
//参数wParam:(BYTE)序号; lParam: 0L--挂机,1L--终端在保留的状态下按免提键退出了保留.
*/
#define WM_ONHOOK WM_USER+704
/*
//来电时发送来电号码.
//参数wParam:(BYTE)序号; lParam:char*.
//普通的号码长度>1;如果长度是1,号码是2,那代表“出局”,号码是1,那代表“保密”。
*/
#define WM_CALLERID WM_USER+705
/*
//来电响铃发此消息.
//参数wParam:(BYTE)序号; lParam: (BYTE)0x01—表示一次铃声响;0x00—表示此次铃声结束
*/
#define WM_RING WM_USER+706
/*
//通话过程中,收到本端DTMF键值时,发此消息.
//参数wParam: (BYTE)序号; lParam: char.
*/
#define WM_KEY WM_USER+707
/*
//留言过程中,话机接听电话,停止留言,发此消息.
//参数wParam: (BYTE)序号; lParam: 0L.
*/
#define WM_STOPLY WM_USER+708
/*
//通话过程中,收到话机按“静音”键
//参数wParam: (BYTE)序号; lParam: (BYTE)0x01--静音开启;0x00--静音关闭.
*/
#define WM_MUTE WM_USER+709
extern "C" {
//---------from PC to Phone-------------------------
// 若无说明,则返回 0 代表成功
USBDLL_API int _stdcall InitDll(); //初始化,仅调用一次
USBDLL_API int _stdcall OffHookCtrl(int iDevIdx); //发送摘机命令
USBDLL_API int _stdcall HangUpCtrl(int iDevIdx); //发送挂机命令
USBDLL_API int _stdcall StartDial(int iDevIdx,const char* szDest); //发送拨号命令
USBDLL_API int _stdcall Bell(int iDevIdx,BYTE mode); //设置振铃开或关,mode: 0--关闭; 1--打开
USBDLL_API int _stdcall SendDTMF(int iDevIdx,const char* szDTMF); //与StartDial功能相似,供二次拨号用
USBDLL_API int _stdcall BindWindow(HWND hwnd); //绑定窗口,所有事件发送到此窗口,初始化时调用;系统接收消息 WM_DEVICECHANGE 后调用此函数
USBDLL_API int _stdcall UnBindWindow(); //解除窗口绑定, 则所有事件将不会发送到此窗口,窗口销毁时调用此函数
USBDLL_API int _stdcall QueryPhoneStatus(int iDevIdx); //查询话机摘挂机状态 0->挂机,1->摘机
USBDLL_API int _stdcall setLocalRecord(int iDevIdx,BOOL rec); //本地录放音,开 pc 时, rec: false--关闭;true--打开
USBDLL_API int _stdcall setTalkRecord(int iDevIdx,BOOL rec); //通话录音,rec: false--关闭;true--打开
USBDLL_API int _stdcall setLeaveRecord(int iDevIdx,BOOL rec); //留言录音,rec: false--关闭;true--打开
USBDLL_API int _stdcall GetSerialNo(int iDevIdx, char * number); //获取序列号
USBDLL_API int _stdcall SetSerialNo(int iDevIdx, const char * number); //设置序列号
USBDLL_API int _stdcall Flash(int iDevIdx,UINT ivalue); //闪断一下,ivalue--Flash操作的时间长度,取值为0--100ms,1--180ms,2--300ms,3--600ms,4--1000ms之间。
USBDLL_API int _stdcall SetDialTone(int iDevIdx,BYTE mode); //设置拨号音开或关,mode: 0--关闭; 1--打开
USBDLL_API int _stdcall SetAutoAnswer(int iDevIdx,BYTE mode); //设置自动接听开或关,mode: 0--关闭; 1--打开
USBDLL_API int _stdcall SetFlashTime(int iDevIdx,UINT ivalue); //设置Flash值, ivalue 取值为0--100ms,1--180ms,2--300ms,3--600ms,4--1000ms之间
USBDLL_API int _stdcall SetOutcode(int iDevIdx, const char * code); //设置出局码,最多3位
USBDLL_API int _stdcall StartRecordFile(int iDevIdx, const char* strFileName, int iType); //开始录音操作, strFileName: 录音文件名,完整的路径
//如:"C:\\record\\sound.wav"。iType: 录音类型:0:本地录音;1:通话录音;2:留言录音
USBDLL_API int _stdcall StopRecordFile(int iDevIdx); //停止录音
USBDLL_API int _stdcall ZhuanBo(int iDevIdx,UINT ivalue); //转拨闪断一下,ivalue--转拨操作的时间长度,取值为0--100ms,1--180ms,2--300ms,3--600ms,4--1000ms之间。
USBDLL_API int _stdcall Hold(int iDevIdx, BOOL bOn); //bOn--1:开启保留;0:关闭保留
USBDLL_API int _stdcall Mute(int iDevIdx, BOOL bOn); // bOn->1:开启闭音;0:关闭闭音;
}
#endif
protected override void WndProc(ref Message m)
然后判断m的类型,然后自己编写相关的抛出事件,你自己封装出几个你自己需要的事件。你的这个窗体可以显示,也可以隐藏,总之是用来接收这个驱动程序推送消息的。
procedure TForm1.Button6Click(Sender: TObject);
var
iRec:integer;
begin
iRec:= QueryPhoneStatus(0);
if iRec=0 then
label6.Caption :='当前话机状态:挂机'
else if iRec=1 then
label6.Caption :='当前话机状态:摘机';
end;
procedure TForm1.Button7Click(Sender: TObject);
var
iRec:integer;
str:string;
p:pchar;
begin
if edit2.Text ='' then
begin
showmessage('请输入有效的序列号!');
edit2.SetFocus;
exit;
end;
try
str:='select 标志 from [sheet1$] where 序列号='''+edit2.Text+'''';
UserAdoQry(qrysel,str,false);
if qrysel.RecordCount <>0 then
begin
if qrysel.Fields.FieldByName('标志').AsString='1' then
begin
showmessage('该序列号已烧录,系统自动为你获取一个新的序列号。');
ReadSerial;//读取下一个序列号
exit;
end;
end;
try
getmem(p, 255*sizeof(char));
strcopy(p,pchar(edit2.text));
iRec:= SetSerialNo(0,p );
if iRec=0 then
begin
str:='update [sheet1$] set 标志=''1'' where 序列号='''+edit2.Text+'''';
UserAdoQry(qrysel,str,true);
showmessage('设置成功。');
ReadSerial;//读取下一个序列号
end
else
begin
showmessage('设置失败!');
end;
finally
freemem(p);
end;
except
try
getmem(p, 255*sizeof(char));
strcopy(p,pchar(edit2.text));
iRec:= SetSerialNo(0,p );
if iRec=0 then
begin
showmessage('设置成功。');
str:='update [sheet1$] set 标志=''1'' where 序列号='''+edit2.Text+'''';
UserAdoQry(qrysel,str,true);
end
else
begin
showmessage('设置失败!');
end;
finally
freemem(p);
end;
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var
iRec:integer;
sNumber:tstringlist;
p:pchar;
begin
sNumber:= tstringlist.Create;
try
getmem(p, 255*sizeof(char));
iRec:= GetSerialNo(0,sNumber );
if iRec=0 then
begin
strcopy(p,pchar(sNumber));
label8.Caption :='当前话机序列号:'+string(p);
end
else
begin
label8.Caption :='返回序列号失败!-1';
end;
finally
freemem(p);
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
var
iRec:integer;
iValue:integer;
begin
if rb0.Checked then iValue:=0;
if rb1.Checked then iValue:=1;
if rb2.Checked then iValue:=2;
if rb3.Checked then iValue:=3;
if rb4.Checked then iValue:=4;
iRec:=Flash(0,iValue);
end;
procedure TForm1.Button10Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='拨号音关';
iRec:= SetDialTone(0,1);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='拨号音开';
iRec:= SetDialTone(0,0);
end;
end;
procedure TForm1.Button11Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='自动接听关';
iRec:= SetAutoAnswer(0,1);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='自动接听开';
iRec:= SetAutoAnswer(0,0);
end;
end;
procedure TForm1.Button12Click(Sender: TObject);
var
iRec:integer;
iValue:integer;
begin
if rb00.Checked then iValue:=0;
if rb11.Checked then iValue:=1;
if rb22.Checked then iValue:=2;
if rb33.Checked then iValue:=3;
if rb44.Checked then iValue:=4;
iRec:=SetFlashTime(0,iValue);
end;
procedure TForm1.Button13Click(Sender: TObject);
var
iRec:integer;
begin
iRec:=SetOutcode(0,edit3.Text);
end;
procedure TForm1.Button14Click(Sender: TObject);
var
iRec:integer;
sFile:string;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='停止录音';
sFile:=formatdatetime('yyyymmddhhmmss',now)+'.wav';
iRec:=setTalkRecord(0,true);//打开录音通道
iRec:=StartRecordFile(0,sFile,1);//通话录音
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='开始录音';
iRec:= StopRecordFile(0);
iRec:= setTalkRecord(0,false);//关闭录音通道
end;
end;
procedure TForm1.Button15Click(Sender: TObject);
var
iRec:integer;
iValue:integer;
begin
if rb0.Checked then iValue:=0;
if rb1.Checked then iValue:=1;
if rb2.Checked then iValue:=2;
if rb3.Checked then iValue:=3;
if rb4.Checked then iValue:=4;
iRec:=ZhuanBo(0,iValue);
end;
procedure TForm1.Button16Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='关闭保留';
iRec:= Hold(0,true);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='开启保留';
iRec:= Hold(0,false);
end;
end;
procedure TForm1.Button17Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='关闭闭音';
iRec:= Mute(0,true);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='开启闭音';
iRec:= Mute(0,false);
end;
end;
procedure TForm1.Button18Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='录音I/O关';
iRec:= setTalkRecord(0,true);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='录音I/O开';
iRec:= setTalkRecord(0,false);
end;
end;
procedure TForm1.Button19Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='留言I/O关';
iRec:= setLeaveRecord(0,true);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='留言I/O开';
iRec:= setLeaveRecord(0,false);
end;
end;
procedure TForm1.PhoneInit;
var
Locator: OleVariant;
WMI: OleVariant;
RET: OleVariant;
Enum: IEnumVariant;
Tmp: OleVariant;
Value: Cardinal;
aList:TStringList;
begin
try
try
aList:=TStringList.Create;
Locator := CreateOleObject('WbemScripting.SWbemLocator');
WMI := Locator.ConnectServer('.', '', '','');
Ret := WMI.ExecQuery('SELECT * FROM Win32_USBHub');//这里Win32_USBHub为检测项,详见下表
Enum:= IUnknown(RET._NewEnum) as IEnumVariant;
//Tmp为检测到返回的数据集合,其中PNPDeviceID为集合中的对象,包含了PID和VID码
while (Enum.Next(1, Tmp, Value) = S_OK) do aList.Add(Tmp.PNPDeviceID);
//if aList.IndexOf('USB\VID_1267&PID_5AA5\5&16BBD8B4&0&1')>0 then //设备存在
if pos('USB\VID_1267',alist.CommaText)>0 then
begin
//BindWindow(form1.Handle);//绑定窗口
BindWindow(handle);//绑定窗口
StatusBar1.Panels[0].Text:='已连接';
button1.Tag :=100;
button1.Caption :='解除绑定';
end
else
begin
button1.Tag :=0;
button1.Caption :='窗口绑定';
BindWindow(handle);//绑定窗口
StatusBar1.Panels[0].Text:='已断开';
end;
finally
alist.Destroy;
end;
except
on e:exception do
exit;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitDll;
PhoneInit;
end;
procedure TForm1.Button20Click(Sender: TObject);
type
TIntFunc=function(i:integer):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary('usbdll.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('OffHookCtrl'));
if Tp<>nil
then begin
Tf:=TIntFunc(Tp);
IntToStr(Tf(0)); {调用OffHookCtrl函数}
end
else
ShowMessage('OffHookCtrl函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('usbdll.dll没有找到');
end;
procedure TForm1.ONOFFHOOK(s: string);
type
TIntFunc=function(i:integer):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary('usbdll.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar(s));
if Tp<>nil
then begin
Tf:=TIntFunc(Tp);
IntToStr(Tf(0)); {调用OffHookCtrl函数}
end
else
ShowMessage(s+'函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('usbdll.dll没有找到');
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
UnbindWindow;
end;
procedure TForm1.Button21Click(Sender: TObject);
begin
opend.Execute;
edit5.Text :=opend.FileName;
if edit5.Text ='' then exit;
qrysel.Close;
qrysel.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+ edit5.Text +';Extended Properties=Excel 8.0;Persist Security Info=False';
ReadSerial;
end;
procedure TForm1.ReadSerial;
var
str:string;
begin
str:='select top 1 序列号 from [sheet1$] where 标志<>1';
UserAdoQry(qrysel,str,false);
if qrysel.RecordCount <>0 then
begin
qrysel.First;
edit2.Text :=qrysel.Fields.fieldbyname('序列号').AsString ;
end
else
begin
showmessage('没有有效的序列号。');
edit2.Text :='';
end;
end;
procedure TForm1.UserAdoQry(TheAdoQuery: TAdoQuery; SQLString: string;
EXE: Boolean);
begin
with TheAdoQuery do
begin
close;
SQL.Clear;
SQL.Add(SQLString);
//sql.Append(sqlstring);
if not ExE then
open
Else
ExecSQL;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ComCtrls,ComObj,OleCtrls,ActiveX, DB, ADODB;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Button1: TButton;
Button2: TButton;
Button4: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button3: TButton;
Label4: TLabel;
Edit1: TEdit;
Button5: TButton;
Label5: TLabel;
Button6: TButton;
Label6: TLabel;
Button8: TButton;
Label8: TLabel;
Button9: TButton;
Label9: TLabel;
GroupBox2: TGroupBox;
rb0: TRadioButton;
rb1: TRadioButton;
rb2: TRadioButton;
rb3: TRadioButton;
rb4: TRadioButton;
Button10: TButton;
Label10: TLabel;
Button11: TButton;
Label11: TLabel;
Button12: TButton;
Label12: TLabel;
GroupBox3: TGroupBox;
rb00: TRadioButton;
rb11: TRadioButton;
rb22: TRadioButton;
rb33: TRadioButton;
rb44: TRadioButton;
Button13: TButton;
Label13: TLabel;
Edit3: TEdit;
Button14: TButton;
Label14: TLabel;
Button15: TButton;
Button16: TButton;
Label15: TLabel;
Button17: TButton;
Label16: TLabel;
GroupBox4: TGroupBox;
Button18: TButton;
Button19: TButton;
Label17: TLabel;
StatusBar1: TStatusBar;
Edit4: TEdit;
Button20: TButton;
GroupBox5: TGroupBox;
Label7: TLabel;
Edit2: TEdit;
Button7: TButton;
Label18: TLabel;
Edit5: TEdit;
Button21: TButton;
qrySel: TADOQuery;
OpenD: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button20Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button21Click(Sender: TObject);
private
{ Private declarations }
procedure WMDeviceChange(var Msg:TMessage);message WM_DEVICECHANGE;
procedure WM_DEVICECONNECT(var Msg:TMessage);message WM_USER+701; //设备连接时
procedure WM_DEVICEDISCONNECT(var Msg:TMessage);message WM_USER+702; //设备断开时
procedure WM_OFFHOOK(var Msg:TMessage);message WM_USER+703; //摘机
procedure WM_ONHOOK(var Msg:TMessage);message WM_USER+704; //挂机
procedure WM_CALLERID(var Msg:TMessage);message WM_USER+705; //来电
procedure WM_RING(var Msg:TMessage);message WM_USER+706; //振铃
procedure WM_KEY(var Msg:TMessage);message WM_USER+707; //按键
procedure WM_STOPLY(var Msg:TMessage);message WM_USER+708; //停止留言
procedure WM_MUTE(var Msg:TMessage);message WM_USER+709; //静音
public
{ Public declarations }
procedure PhoneInit;//判断设备是否已连接,连接之后进行初始化。
procedure ONOFFHOOK(s:string);//摘挂机
procedure UserAdoQry(TheAdoQuery:TAdoQuery;SQLString:string;EXE:Boolean);
procedure ReadSerial;//读取序列号
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function InitDll:integer;stdcall;external 'usbdll.dll'; //
function BindWindow(hwnd:THandle):integer;stdcall;external 'usbdll.dll'; //窗口绑定
function UnBindWindow:integer;stdcall;external 'usbdll.dll'; //窗口绑定
//function OffHookCtrl(iDevIdx:integer):integer;stdcall;external 'usbdll.dll'; //摘机
function HangUpCtrl(iDevIdx:integer):integer;stdcall;external 'usbdll.dll'; //挂机
function setLocalRecord(iDevIdx:integer;rec:boolean):integer;stdcall;external 'usbdll.dll'; //PC开/关 TRUE是开 FALSE是关
function setTalkRecord(iDevIdx:integer;rec:boolean):integer;stdcall;external 'usbdll.dll'; //录音开/关 TRUE是开 FALSE是关
function setLeaveRecord(iDevIdx:integer;rec:boolean):integer;stdcall;external 'usbdll.dll'; //留言开/关 TRUE是开 FALSE是关
function StartDial(iDevIdx:integer;szDest:pchar):integer;stdcall;external 'usbdll.dll'; //拨号
function Bell(iDevIdx:integer;mode:byte):integer;stdcall;external 'usbdll.dll'; //振铃开关 0关闭 1 打开
function QueryPhoneStatus(iDevIdx:integer):integer;stdcall;external 'usbdll.dll'; //查询话机状态 0是挂机 1是摘机
function SetSerialNo(iDevIdx:integer;number:string):integer;stdcall;external 'usbdll.dll'; //设置序列号
function GetSerialNo(iDevIdx:integer;number:tstringlist):integer;stdcall;external 'usbdll.dll'; //获取序列号
function SetFlashTime(iDevIdx:integer;ivalue:integer):integer;stdcall;external 'usbdll.dll'; //设置FLASH闪断时间
function Flash(iDevIdx:integer;ivalue:integer):integer;stdcall;external 'usbdll.dll'; //FLASH闪断
function ZhuanBo(iDevIdx:integer;ivalue:integer):integer;stdcall;external 'usbdll.dll'; //ZhuanBo
function SetDialTone(iDevIdx:integer;mode:byte):integer;stdcall;external 'usbdll.dll'; //拨号音开关 0关闭 1 打开
function SetAutoAnswer(iDevIdx:integer;mode:byte):integer;stdcall;external 'usbdll.dll'; //自动接听开关 0关闭 1 打开
function SetOutcode(iDevIdx:integer;code:string):integer;stdcall;external 'usbdll.dll'; //设置出局码
function StartRecordFile(iDevIdx:integer;strFileName:string;iType:integer):integer;stdcall;external 'usbdll.dll'; //录音操作
function StopRecordFile(iDevIdx:integer):integer;stdcall;external 'usbdll.dll'; //停止录音
function Hold(iDevIdx:integer;bOn:boolean):integer;stdcall;external 'usbdll.dll'; //保留 0关闭 1 打开
function Mute(iDevIdx:integer;bOn:boolean):integer;stdcall;external 'usbdll.dll'; //静音 0关闭 1 打开
procedure TForm1.WMDeviceChange(var Msg:TMessage);
begin
case msg.WParam of
32768:exit;//dlginfo('USB插入。');
32772:exit;//dlginfo('USB拔出。');
end;
PhoneInit;
end;
procedure TForm1.WM_DEVICECONNECT(var Msg:TMessage);
begin
//showmessage('设备连接');
end;
procedure TForm1.WM_DEVICEDISCONNECT(var Msg:TMessage);
begin
//showmessage('设备断开');
end;
procedure TForm1.WM_OFFHOOK(var Msg:TMessage);
begin
//showmessage('摘机');
button2.Tag :=100;
button2.Caption :='挂机';
end;
procedure TForm1.WM_ONHOOK(var Msg:TMessage);
begin
//showmessage('挂机');
button2.Tag :=0;
button2.Caption :='摘机';
edit4.Text :='';
//if msg.LParam =0 then showmessage('挂机');
//if msg.LParam =1 then showmessage('免提退出');
end;
procedure TForm1.WM_CALLERID(var Msg:TMessage);
var
str:string;
begin
//showmessage(inttostr(msg.LParam));
str:=pchar(msg.lparam);
edit4.Text :=StringReplace(str, #0, '',[rfReplaceAll, rfIgnoreCase]);
str:=edit4.Text;
//showmessage(inttostr(length(edit4.Text) ));
end;
procedure TForm1.WM_RING(var Msg:TMessage);
var
str:string;
bt:byte;
begin
bt:=byte(msg.LParam );
//bt 0 振铃开始 1振铃结束
//showmessage(inttostr(bt));
end;
procedure TForm1.WM_KEY(var Msg:TMessage);
var
str:string;
begin
str:=wideChar(msg.lparam);
edit4.Text :=edit4.Text +str;
end;
procedure TForm1.WM_STOPLY(var Msg:TMessage);
var
str:string;
begin
//停止留言
end;
procedure TForm1.WM_MUTE(var Msg:TMessage);
var
str:string;
bt:byte;
begin
bt:=byte(msg.LParam );
//bt 0 静音关闭 1静音开启
if bt=1 then
begin
button17.Tag :=100;
button17.Caption :='关闭闭音';
end
else if bt=0 then
begin
button17.Tag :=0;
button17.Caption :='开启闭音';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='解除绑定';
iRec:=BindWindow(0);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='窗口绑定';
iRec:=UnBindWindow;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
iRec:integer;
begin
//if tbutton(sender).Tag =0 then iRec:=offhookctrl(0) else iRec:=HangUpCtrl(0);
if tbutton(sender).Tag =0 then ONOFFHOOK('OffHookCtrl') else ONOFFHOOK('HangUpCtrl');
end;
procedure TForm1.Button4Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='PC关';
iRec:= setLocalRecord(0,true);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='PC开';
iRec:= setLocalRecord(0,false);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
iRec:integer;
p:pchar;
begin
if edit1.Text ='' then exit;
try
getmem(p, 255*sizeof(char));
strcopy(p,pchar(edit1.text));
iRec:= StartDial(0,p );
finally
freemem(p);
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
iRec:integer;
begin
if tbutton(sender).Tag =0 then
begin
tbutton(sender).Tag :=100;
tbutton(sender).Caption :='振铃开';
iRec:= Bell(0,0);
end
else
begin
tbutton(sender).Tag :=0;
tbutton(sender).Caption :='振铃关';
iRec:= Bell(0,1);
end;
end;