⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.pas

📁 三汇CTI示例程序源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Shpa3api, ExtCtrls;

type
  TMainForm = class(TForm)
    LVMain: TListView;
    Label1: TLabel;
    RdBtnDefault: TRadioButton;
    RdBtnALaw: TRadioButton;
    RdBtnULaw: TRadioButton;
    Label2: TLabel;
    CmbBxListenCh: TComboBox;
    BtnStartListen: TButton;
    BtnStopListen: TButton;
    RdBtnIMA: TRadioButton;
    RdBtnGC8: TRadioButton;
    RdBtnG729A: TRadioButton;
    BtnExit: TButton;
    MainTimer: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BtnExitClick(Sender: TObject);
    procedure RdBtnDefaultClick(Sender: TObject);
    procedure RdBtnALawClick(Sender: TObject);
    procedure RdBtnULawClick(Sender: TObject);
    procedure RdBtnIMAClick(Sender: TObject);
    procedure RdBtnGC8Click(Sender: TObject);
    procedure RdBtnG729AClick(Sender: TObject);
    procedure BtnStartListenClick(Sender: TObject);
    procedure BtnStopListenClick(Sender: TObject);
    procedure CmbBxListenChChange(Sender: TObject);
    procedure MainTimerTimer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  CH_STATE =
  (
    CH_IDLE,
    CH_RING,
    CH_ACTIVE,
    CH_OFFLINE,
    CH_WAITFOR_ONHOOK
  );

  CH_LISTEN =
  (
    UNLISTEN,
    LISTEN
  );
  
  CH_RECORD =
  (
    UNRECORD,
    RECORDED
  );
  
  DIRECTION =
  (
    UNKNOWN,
    UP,
    DOWN
  );

const
  MAX_CALLID_LEN = 50;
  MAX_LCD_LEN = 300;
  MAX_ERRMSG_LEN = 300;

type
  PCHANNEL = ^CHANNEL;
  CHANNEL = record
    WorkState: CH_STATE;
    IsListen: CH_LISTEN;
    IsRecord: CH_RECORD;
    pCallID: array [0..MAX_CALLID_LEN] of Char;
    LCDLen: Integer;
    CallIDLen: Integer;
    Lcd: array [0..MAX_LCD_LEN] of Char;
    //Lcd: PChar;
    Dir: DIRECTION;
    pErrMsg: array [0..MAX_ERRMSG_LEN] of Char;
  end;

var
  MainForm: TMainForm;
  AppTitle: PChar;
  szErrMsg: PChar;
  IniShConfig, IniShIndex: PChar;
  iMaxUsableBoard, iMaxCfgBoard: Integer;
  iMaxCh: Integer;
  iCurCh: Integer;
  iChType: Integer;
  iRecFormat: Integer;
  iListenChannel: Integer;
  ChannelState: array [0..200] of CHANNEL;
  EventSetInfo: EVENT_SET_INFO;
  EventSet: PEVENT_SET_INFO;
  function AppEventCallBackAFunc(pEvent: PSSM_EVENT):Integer; stdcall;
  procedure UpdateChannelState();
  procedure StartRecord(ch: Integer);
  procedure StopRecord(ch: Integer);
  procedure ClearCallID(pEvent: PSSM_EVENT);
  procedure GetCallID(pEvent: PSSM_EVENT);

implementation

//uses Shpa3api;

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
var
  iCh: Integer;
  ListColumn: TListColumn;
  ListItem: TListItem;
  iColumnIndex: Integer;
begin
  //
  AppTitle := 'SHR_DEvent_Delphi';

  IniShConfig := 'ShConfig.ini';
  IniShIndex := 'ShIndex.ini';
  GetMem(szErrMsg, 255);
  if SsmStartCti(IniShConfig, IniShIndex)<>0 then
  begin
    SsmGetLastErrMsg(szErrMsg);
    MessageBox(MainForm.Handle, szErrMsg, AppTitle, MB_OK or MB_ICONERROR);
    Application.Terminate;
    Exit;
  end;

  iMaxUsableBoard := SsmGetMaxUsableBoard();
  iMaxCfgBoard := SsmGetMaxCfgBoard();
  if iMaxUsableBoard<>iMaxCfgBoard then
  begin
    SsmGetLastErrMsg(szErrMsg);
    MessageBox(MainForm.Handle, szErrMsg, AppTitle, MB_OK or MB_ICONERROR);
    Application.Terminate;
    Exit;
  end;

  EventSet := @EventSetInfo;
  EventSet.dwWorkMode := 2;
  EventSet.lpHandlerParam := @AppEventCallBackAFunc;
  if SsmSetEvent($FFFF, -1, True, EventSet) = -1 then
  begin
    SsmGetLastErrMsg(szErrMsg);
    MessageBox(MainForm.Handle, szErrMsg, AppTitle, MB_OK or MB_ICONERROR);
    Application.Terminate;
    Exit;
  end;

  iMaxCh := SsmGetMaxCh();
  iListenChannel := iMaxCh;

  //InitChList();

  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Channel num';
  ListColumn.Width := 80;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Channel state';
  ListColumn.Width := 90;
  ListColumn.Alignment := taRightJustify;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Listen state';
  ListColumn.Width := 90;
  ListColumn.Alignment := taRightJustify;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Record state';
  ListColumn.Width := 85;
  ListColumn.Alignment := taRightJustify;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Phone num';
  ListColumn.Width := 70;
  ListColumn.Alignment := taRightJustify;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'LCD info';
  ListColumn.Width :=230;
  ListColumn.Alignment := taRightJustify;
  ListColumn := MainForm.LVMain.Columns.Add;
  ListColumn.Caption := 'Call direction';
  ListColumn.Width := 98;
  ListColumn.Alignment := taRightJustify;

  //UpdateChList();

  for iCh := 0 to iMaxCh - 1 do
  begin
    iChType := SsmGetChType(iCh);
    if iChType = 12 then
    begin
      ListItem := LVMain.Items.Add;
      ListItem.Caption := IntToStr(iCh);  //Ch
      for iColumnIndex := 1 to LVMain.Columns.Count - 1 do
      begin
        ListItem.SubItems.Add('');
      end;

      CmbBxListenCh.AddItem(IntToStr(iCh), Self);

      ChannelState[iCh].WorkState := CH_IDLE;		//Off line state
      ChannelState[iCh].IsListen := UNLISTEN;        //Unlisten
      ChannelState[iCh].IsRecord := UNRECORD;        //Unrecord
      ChannelState[iCh].pCallId := '';			//Phone number is null
      ChannelState[iCh].Lcd := '';              //LCD info is null
      ChannelState[iCh].Dir := UNKNOWN ;             //Call direction is "UNKNOWN"

      if SsmGetChState(iCh) = S_CALL_OFFLINE then
      begin
        ChannelState[iCh].WorkState := CH_OFFLINE;
      end;
    end;
  end;

  iCurCh := 0;

  RdBtnDefault.Checked := True;
  iRecFormat := -1;

  CmbBxListenCh.ItemIndex := 0;

  MainTimer.Enabled := True;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  SsmCloseCti();
end;

procedure TMainForm.BtnExitClick(Sender: TObject);
begin
  Close;
end;

procedure UpdateChannelState();
var
  i: Integer;
  num: Integer;
  strtemp: string;
begin
  //
  num := 0;
  for i := 0 to iMaxCh - 1 do
  begin
    if SsmGetChType(i) = 12 then
    begin
      case ChannelState[i].WorkState of
        CH_IDLE: strtemp := 'Idle';
        CH_RING: strtemp := 'Ringing';
        CH_ACTIVE: strtemp := 'Active';
        CH_OFFLINE: strtemp := 'Offline';
        CH_WAITFOR_ONHOOK: strtemp := 'WaitforOnhook';
      end;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[0] then
      begin
        MainForm.LVMain.Items[num].SubItems[0] := strtemp;
      end;

      case ChannelState[i].IsListen of
        LISTEN: strtemp := 'Listen';
        UNLISTEN: strtemp := 'Unlisten';
      end;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[1] then
      begin
        MainForm.LVMain.Items[num].SubItems[1] := strtemp;
      end;

      case ChannelState[i].IsRecord of
        RECORDED: strtemp := 'Record';
        UNRECORD: strtemp := 'Unrecord';
      end;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[2] then
      begin
        MainForm.LVMain.Items[num].SubItems[2] := strtemp;
      end;

      strtemp := ChannelState[i].pCallId;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[3] then
      begin
        MainForm.LVMain.Items[num].SubItems[3] := strtemp;
      end;

      strtemp := ChannelState[i].Lcd;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[4] then
      begin
        MainForm.LVMain.Items[num].SubItems[4] := strtemp;
      end;

      case ChannelState[i].Dir of
        UNKNOWN: strtemp := 'Unknown';
        UP: strtemp := 'Call out';
        DOWN: strtemp := 'Call in';
      end;
      if strtemp <> MainForm.LVMain.Items[num].SubItems[5] then
      begin
        MainForm.LVMain.Items[num].SubItems[5] := strtemp;
      end;

      num := num + 1;
    end;
  end;
end;

function AppEventCallBackAFunc(pEvent: PSSM_EVENT):Integer; stdcall;
var
  //dwCondition: DWORD;
  ch: Integer;
  //pLcd: PChar;
begin
  //
  //dwCondition := pEvent.dwParam and $ffff;
  ch := pEvent.nReference;
  case ChannelState[ch].WorkState of
    CH_IDLE:
    //begin
      case pEvent.wEventCode of
        E_CHG_CHState:
          if (pEvent.dwParam and $ffff) = S_CALL_OFFLINE then
          begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -