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

📄 atrk4dlg.cpp

📁 三汇CTI示例程序源码
💻 CPP
字号:
// ATrk4Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "ATrk4.h"
#include "ATrk4Dlg.h"
#include "../../../../../api/vc6.0/inc/shpa3api.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CATrk4Dlg dialog

CATrk4Dlg::CATrk4Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CATrk4Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CATrk4Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CATrk4Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CATrk4Dlg)
	DDX_Control(pDX, IDC_LIST_TRK, m_TrkChList);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CATrk4Dlg, CDialog)
	//{{AFX_MSG_MAP(CATrk4Dlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CATrk4Dlg message handlers

BOOL CATrk4Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	if(InitCtiSystem() == false)
	{
		PostQuitMessage(0);
		return false;
	}
	InitATrunkCh();

	InitDTrunkListCtrl();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CATrk4Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CATrk4Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CATrk4Dlg::InitDTrunkListCtrl()
{
	static int ColumnWidth[5] = {36, 85, 70, 70, 200};
	LV_COLUMN lvc;
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	
	lvc.iSubItem = 0;
	lvc.pszText = "ChannelId" ;
	lvc.cx = ColumnWidth[0];
	m_TrkChList.InsertColumn(0,&lvc);

	lvc.iSubItem = 1;
	lvc.pszText = "Channel State";
	lvc.cx = ColumnWidth[1];
	m_TrkChList.InsertColumn(1,&lvc);

	lvc.iSubItem = 2;
	lvc.pszText = "CallerId";
	lvc.cx = ColumnWidth[2];
	m_TrkChList.InsertColumn(2,&lvc);

	lvc.iSubItem = 3;
	lvc.pszText = "DTMF";
	lvc.cx = ColumnWidth[3];
	m_TrkChList.InsertColumn(3,&lvc);

	lvc.iSubItem = 4;
	lvc.pszText = "ErrMessage";
	lvc.cx = ColumnWidth[4];
	m_TrkChList.InsertColumn(4,&lvc);


	char dig[3];
	for(int i = 0; i < nTotATrkCh; i++)
	{
		if ( ATrkCh[i].EnCalled )
		m_TrkChList.InsertItem(i,_itoa(i,dig,10));
	}
}

void CATrk4Dlg::UpDateATrunkChListCtrl()
{
	CString state;
	char tmpstr[30];
	int nIndex;

	nIndex = 0;
	for(int i=0; i<nTotATrkCh; i++)
	{
		if ( ATrkCh[i].EnCalled )
		{
			switch( ATrkCh[i].Step ) 
			{
			case TRK_IDLE:					state = "Idle";				break ;
			case TRK_WAIT_CONNECT:			state = "WaitForConn";			break ;
			case TRK_CHECK_PLAY_WELCOM:		state = "Play Welcom";		break ;
			case TRK_CHECK_PLAY_SELECT:		state = "WaitForKey";		break ;
			case TRK_CHECK_REC_START:		state = "WaitForRecordStart";		break ;
			case TRK_CHECK_REC_END:			state = "Recording";			break ;
			case TRK_CHECK_PLAY_RECORD:		state = "Play Message";			break ;
			case TRK_CHECK_PLAY_BYEBYE:		state = "Play Bye";		break ;
			case TRK_CHECK_PLAY_PASSWORD:	state = "Play Password";			break ;
			default:						state = "Undefined";			break;
			}
			m_TrkChList.GetItemText( nIndex, 1, tmpstr, 29 ) ;
			if ( state != tmpstr ) 
				m_TrkChList.SetItemText( nIndex, 1, state.GetBuffer(30) );
						 
			m_TrkChList.GetItemText( nIndex, 2, tmpstr, 29 ) ;		//display caller ID
			if ( tmpstr != ATrkCh[i].pCallerId ) 
				m_TrkChList.SetItemText( nIndex, 2, ATrkCh[i].pCallerId );
						 
			if( ATrkCh[i].Step == TRK_IDLE )
			{
				state = "";
				if ( state != tmpstr ) 
					m_TrkChList.SetItemText( nIndex, 3, state.GetBuffer(30) );				
			}
			else
			{
				state.Empty();
				if( SsmGetDtmfStr(i, state.GetBuffer(50)) > 0 )		//receive and display DTMF keys
				{
				
					m_TrkChList.GetItemText( nIndex, 3, tmpstr, 29 );
					if ( state != tmpstr ) 
						m_TrkChList.SetItemText( nIndex, 3, state.GetBuffer(30) );				
				}
			}
			
			
			m_TrkChList.GetItemText( nIndex, 4, tmpstr, 29 );		//display error messages occured
			if ( ATrkCh[i].pErrMsg != tmpstr ) 
				m_TrkChList.SetItemText( nIndex, 4, ATrkCh[i].pErrMsg );
			nIndex = nIndex + 1;
		}
	}
}

void CATrk4Dlg::InitATrunkCh()
{
	nTotATrkCh =SsmGetMaxCh();
	for(int i=0; i<nTotATrkCh; i++)
	{
		ATrkCh[i].EnCalled = false;

		int nDirection;
		if( SsmGetAutoCallDirection(i,&nDirection) == 1 ) //auto connection is supported
		{
			if( nDirection == 0 || nDirection == 2 ) //enable call in
			{
				  ATrkCh[i].Step = TRK_IDLE;				  
				  ATrkCh[i].EnCalled = true;
			}
		}		
	}
}

bool CATrk4Dlg::InitCtiSystem()
{
	int nIsSsmStartCtiOK = SsmStartCti("ShConfig.ini", "ShIndex.ini");
	if(nIsSsmStartCtiOK != 0)
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);
		return FALSE;
	}
	
	if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);
	}
	
	// set event callback handle.
	EVENT_SET_INFO EventSet;
	EventSet.dwWorkMode = EVENT_CALLBACK;	
	EventSet.lpHandlerParam = EventCallBackProc;
	EventSet.dwUser = (DWORD)this;
	SsmSetEvent(-1, -1, TRUE, &EventSet);
	nTimer = SsmStartTimer(200, 1);

	return true;
}

void CATrk4Dlg::AppErrorHandler(int ch)
{
	SsmHangup(ch);
	SsmGetLastErrMsg(ATrkCh[ch].pErrMsg.GetBuffer(200));
	ATrkCh[ch].Step = TRK_IDLE;
}

void CATrk4Dlg::OnDestroy() 
{
	// TODO: Add your message handler code here
	SsmCloseCti();		
	CDialog::OnDestroy();	
}


int CATrk4Dlg::EventCallBackProc(WORD wEvent, int nReference, DWORD dwParam, DWORD dwUser)
{
	CATrk4Dlg *pATrk4Dlg = (CATrk4Dlg *)dwUser;
	CFileFind cf;
	CString csDtmfStr;
	char tmp[100];
	int ch;	
	switch(wEvent) {
	case E_SYS_TIMEOUT://Timer event
		if(pATrk4Dlg->nTimer== nReference)//nReference;//event output reference 
		{
			for(ch=0; ch<pATrk4Dlg->nTotATrkCh; ch++ ) 
			{
				if ( pATrk4Dlg->ATrkCh[ch].EnCalled ) 
				{
					if (pATrk4Dlg->ATrkCh[ch].Step == TRK_CHECK_REC_START) {
						if(++pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter > 300) //wait 60 = 300*200 seconds for DTMF-key
						{
							if ( SsmPlayIndexString( ch, "Byebye" )== -1 ) 
								pATrk4Dlg->AppErrorHandler(ch);
							else
							{
								pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_BYEBYE;
							}
						}
					}
					else if (TRK_CHECK_PLAY_SELECT == pATrk4Dlg->ATrkCh[ch].Step) 
					{						
						if(++pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter > 300) // wait DTMF key for maximum 60 = 300*200 seconds 
						{							
							if ( SsmPlayIndexString( ch, "Byebye" )== -1 ) 
								pATrk4Dlg->AppErrorHandler(ch);
							else
							{
								pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_BYEBYE;
							}
						}
					}
				}
			}
			
			pATrk4Dlg->UpDateATrunkChListCtrl();
		}
		break;
	case E_CHG_ChState://change in state of channel 
		ch = nReference;
		pATrk4Dlg->ATrkCh[ch].lineState = int(dwParam &0xFFFF);
		switch(pATrk4Dlg->ATrkCh[ch].lineState)
		{
		case S_CALL_RINGING:
			if( pATrk4Dlg->ATrkCh[ch].Step == TRK_IDLE)  //ring detected
			{
				SsmPickup(ch);
				SsmGetCallerId(ch, pATrk4Dlg->ATrkCh[ch].pCallerId.GetBuffer(100));
				pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
				pATrk4Dlg->ATrkCh[ch].Step = TRK_WAIT_CONNECT;				
			}
			break;
			
		case S_CALL_TALKING:
			if( pATrk4Dlg->ATrkCh[ch].Step == TRK_WAIT_CONNECT) 
			{
				SsmClearFileList(ch);
				if (SsmAddToFileList(ch,"..\\..\\..\\..\\..\\DemoVoc\\Welcom1.voc",-1,0,0xffffffff)==-1 || 
					SsmAddToFileList(ch,"..\\..\\..\\..\\..\\DemoVoc\\Welcom2.voc",-1,0,0xffffffff)==-1) 
				{
					pATrk4Dlg->AppErrorHandler(ch);
				}
				else 
				{
					if(SsmPlayFileList(ch) == -1) 
						pATrk4Dlg->AppErrorHandler(ch);
					else 
					{
						pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_WELCOM;
					}
				}
			}
			break;
		case S_CALL_PENDING://pending state 
			pATrk4Dlg->AppErrorHandler(ch);
			break;
		}
		break;
		
		case E_PROC_PlayEnd://end of playback 
			ch = nReference;
			if (pATrk4Dlg->ATrkCh[ch].Step == TRK_CHECK_PLAY_WELCOM) {
				if(dwParam == 4)
					pATrk4Dlg->AppErrorHandler(ch);
				else
				{
					SsmSetDtmfStopPlay(ch,1);	//enable DTMF-Stop-Play function
					SsmClearRxDtmfBuf(ch);
					
					pATrk4Dlg->ATrkCh[ch].pErrMsg = "";
					if(SsmPlayIndexString(ch,"Select") == -1)
						pATrk4Dlg->AppErrorHandler(ch);
					else
					{
						pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
						pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_SELECT;					
					}
				}			
			}
			else if (TRK_CHECK_PLAY_SELECT == pATrk4Dlg->ATrkCh[ch].Step) 
			{
				if(dwParam == 2) //CHKPLAY_DTMF_END
				{
					SsmGet1stDtmf(ch,tmp);
					SsmClearRxDtmfBuf(ch);
					switch(*tmp)
					{
					case '1': //DTMF=1: record to file "test.voc"
						if(SsmPlayIndexString(ch,"RecPrompt") == -1)	//play "press any key to start, and any key again to stop".
							pATrk4Dlg->AppErrorHandler(ch);
						else 
						{
							pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
							pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_REC_START;
						}
						break;
						
					case '2':		//DTMF=2: play recorded file "test.voc"
						if(cf.FindFile("test.voc", 0) != 0) 
							if(SsmPlayFile(ch,"test.voc",-1,0,0xFFFFFFFF) == -1) 
								pATrk4Dlg->AppErrorHandler(ch);
							else
								pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_RECORD;
							else 
								if(SsmPlayIndexString(ch,"FileNotFound") == -1)	//play "file not found" message
									pATrk4Dlg->AppErrorHandler(ch);
								else
									pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_RECORD;
								break ;
								
					case '3':			//DTMF=3: play user's password,some sample digital
						SsmSetDtmfStopPlay( ch, 0); //disable DTMF-Stop-Play function while playing password
						if(SsmPlayIndexString(ch,"YourPasswordIs,1,2,3,4") == -1)	//play "your password is 1234".
						{	
							pATrk4Dlg->AppErrorHandler(ch);
						}
						else 
						{
							pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_PASSWORD;
						}
						break;
						
					case '0':			//DTMF='0':  end of service,play "Byebye"
						if ( SsmPlayIndexString(ch, "Byebye" )== -1 ) 
							pATrk4Dlg->AppErrorHandler(ch);
						else
							pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_BYEBYE;
						break;
						
					default:	
						SsmSetDtmfStopPlay(ch,1);	//enable DTMF-Stop-Play function
						SsmClearRxDtmfBuf(ch);
						
						pATrk4Dlg->ATrkCh[ch].pErrMsg = "";
						if(SsmPlayIndexString(ch,"Select") == -1)
							pATrk4Dlg->AppErrorHandler(ch);
						else
						{
							pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
							pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_SELECT;
						}
						break;
					}
				}
			}
			else if (TRK_CHECK_PLAY_PASSWORD == pATrk4Dlg->ATrkCh[ch].Step
				|| TRK_CHECK_PLAY_RECORD == pATrk4Dlg->ATrkCh[ch].Step) 
			{
				SsmSetDtmfStopPlay(ch,1);	//enable DTMF-Stop-Play function
				SsmClearRxDtmfBuf(ch);
				
				pATrk4Dlg->ATrkCh[ch].pErrMsg = "";
				if(SsmPlayIndexString(ch,"Select") == -1)
					pATrk4Dlg->AppErrorHandler(ch);
				else
				{
					pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
					pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_SELECT;
				}			
			}
			else if (TRK_CHECK_PLAY_BYEBYE == pATrk4Dlg->ATrkCh[ch].Step) {
				SsmHangup(ch);
				pATrk4Dlg->ATrkCh[ch].Step = TRK_IDLE;
				break ;
			}
			break;
			
	case E_CHG_RcvDTMF://receive DTMF
		ch = nReference;
		if (pATrk4Dlg->ATrkCh[ch].Step == TRK_CHECK_REC_START) {
			SsmClearRxDtmfBuf(ch);
			if( SsmRecToFile(ch,"test.voc", -1,0L,10L*8000L,10,0) == -1) //start from 16000L,maxmium 10 seconds
				pATrk4Dlg->AppErrorHandler(ch);
			else
				pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_REC_END;
		}
		else if (pATrk4Dlg->ATrkCh[ch].Step == TRK_CHECK_REC_END) {
			if (SsmChkRecToFile(ch)==1) SsmStopRecToFile(ch);
			SsmSetDtmfStopPlay(ch,1);	//enable DTMF-Stop-Play function
			SsmClearRxDtmfBuf(ch);
			
			pATrk4Dlg->ATrkCh[ch].pErrMsg = "";
			if(SsmPlayIndexString(ch,"Select") == -1)
				pATrk4Dlg->AppErrorHandler(ch);
			else
			{
				pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
				pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_SELECT;
			}
		}

		break;
		
	case E_PROC_RecordEnd://end of recording operation 
		ch = nReference;
		if (pATrk4Dlg->ATrkCh[ch].Step == TRK_CHECK_REC_END) {			
			SsmSetDtmfStopPlay(ch,1);	//enable DTMF-Stop-Play function
			SsmClearRxDtmfBuf(ch);
			
			pATrk4Dlg->ATrkCh[ch].pErrMsg = "";
			if(SsmPlayIndexString(ch,"Select") == -1)
				pATrk4Dlg->AppErrorHandler(ch);
			else
			{
				pATrk4Dlg->ATrkCh[ch].dwTimeOutCounter = 0;
				pATrk4Dlg->ATrkCh[ch].Step = TRK_CHECK_PLAY_SELECT;
			}
		}
		break;
	default:
		break;
	}
	
	return 0;
}

⌨️ 快捷键说明

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