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

📄 dialdlg.cpp

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

#include "stdafx.h"
#include "Dial.h"
#include "DialDlg.h"
#include "string.h"
#include "../../../../../api/vc6.0/inc/Shpa3api.h"

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

HANDLE hThread;
/////////////////////////////////////////////////////////////////////////////
// CDialDlg dialog

CDialDlg::CDialDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialDlg)
	m_PhoNumLen = 8;
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDialDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialDlg)
	DDX_Control(pDX, IDC_LIST_USER_CH, m_UserChList);
	DDX_Control(pDX, IDC_LIST_TRK_CH, m_TrkChList);
	DDX_Text(pDX, IDC_PHONE_NUM_LEN, m_PhoNumLen);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDialDlg, CDialog)
	//{{AFX_MSG_MAP(CDialDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_PHONE_NUM_LEN, OnChangePhoneNumLen)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialDlg message handlers

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

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	if(!InitCtiBoard())  return false; 
	
	InitTrunkChList();	
	InitUserChList();

	//DWORD dwThreadID;
	hThread=::CreateThread(NULL,0,MyThreadFunction,this,CREATE_SUSPENDED,NULL);
    ResumeThread(hThread);

	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 CDialDlg::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();
	}
}

HCURSOR CDialDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDialDlg::OnChangePhoneNumLen() 
{
	UpdateData(true);
}

BOOL CDialDlg::InitCtiBoard()
{
	//Initialization of CTI driver
	char CurPath[260],ShIndex[260],ShConfig[260];
	GetCurrentDirectory(200,CurPath);
	strcpy(ShConfig,CurPath);
	strcpy(ShIndex,CurPath);
	strcat(ShConfig,"\\ShConfig.ini");
	strcat(ShIndex,"\\ShIndex.ini");
	if( SsmStartCti(ShConfig,ShIndex) != 0) 
	{
		CString str1;
		SsmGetLastErrMsg(str1.GetBuffer(200));
		AfxMessageBox(str1, MB_OK) ;
		PostQuitMessage(0);
		return false;
    }

	//Initialization of channels on trunk-board

	nTotalCh = SsmGetMaxCh(); 
	for(int i=0; i<nTotalCh; i++)
	{
		ChInfo[i].EnCalled = false;

		if(SsmGetChType(i) == 2 ) // user channel
		{
			SsmSetASDT(i, 1);
			strcpy(ChInfo[i].pPhoNumBuf,"");
			ChInfo[i].nStep = USER_IDLE;
		}
		else
		{
			
			int nDirection;
			if( SsmGetAutoCallDirection(i,&nDirection) == 1 ) //auto connection is supported
			{
				if( nDirection == 1 || nDirection == 2 ) //enable dial
				{
					  ChInfo[i].InUse = 0;
					  strcpy(ChInfo[i].DtmfBuf,"");
					  SsmSetMinVocDtrEnergy( i, 30000);					  
					  ChInfo[i].EnCalled = true;
					  ChInfo[i].nStep = TRK_IDLE;
				}
			}
		}		
	}


	EVENT_SET_INFO EventSet;
	EventSet.dwWorkMode=EVENT_POLLING;
	EventSet.dwOutCondition=1000;
	SsmSetEvent(-1,-1,TRUE,&EventSet);

	nTimer = SsmStartTimer(200, 1);



	

	return true;
}

void CDialDlg::InitTrunkChList()
{
	//Initialization of trunk-channel-state list control
	int ColumnWidth[4] = {40, 85, 60};
	LV_COLUMN lvc;
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	
	lvc.iSubItem = 0;
	lvc.pszText = "Channel Id" ;
	lvc.cx = ColumnWidth[0];
	m_TrkChList.InsertColumn(0,&lvc);

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

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

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

void CDialDlg::InitUserChList()
{
	int ColumnWidth[4] = {40, 85, 60};
	LV_COLUMN lvc;
	lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	lvc.iSubItem = 0;
	lvc.pszText = "ChannelId";
	lvc.cx = ColumnWidth[0];
	m_UserChList.InsertColumn(0,&lvc);

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

	lvc.iSubItem = 2;
	lvc.pszText = "CalledId";
	lvc.cx = ColumnWidth[2];
	m_UserChList.InsertColumn(2,&lvc);
	
	char dig[3];
	for(int i=0; i<nTotalCh; i++)
	{	
		if (SsmGetChType(i)==2) m_UserChList.InsertItem(i, _itoa(i,dig,10));
	}
}

void CDialDlg::DrawUserChState()
{
	CString state ;
	char tmpstr[51];

	for(int i=0,nIndex=0; i<nTotalCh; i++)
	{
		if( SsmGetChType(i) != 2) continue;
		
		switch( ChInfo[i].nStep )
		{
		case USER_IDLE:					state = "Idle";			break ;
		case USER_GET_PHONE_NUM:		state = "Receive Phone Number"; break ;
		case USER_WAIT_DIAL_TONE:		state = "Wait Dial-tone";	break ;
		case USER_WAIT_REMOTE_PICKUP:	state = "Wait Called Party Answer"; break ;
		case USER_TALKING:				state = "Talking";		break ;
		case USER_WAIT_HANGUP:			state = "Wait Station Hangup"; break ;		
		}
		
		m_UserChList.GetItemText(nIndex,1,tmpstr,50); 
		if(state != tmpstr) 
			m_UserChList.SetItemText(nIndex, 1, state.GetBuffer(50) );

		m_UserChList.GetItemText(nIndex,2,tmpstr,50); 
		if(strcmp(ChInfo[i].pPhoNumBuf,tmpstr) != 0) 
			m_UserChList.SetItemText(nIndex, 2, ChInfo[i].pPhoNumBuf);
		
		nIndex++;
	}
}
		

void CDialDlg::DrawTrunkChState()
{
	CString state;
	char tmpstr[51];

	for(int i=0, nIndex = 0; i<nTotalCh; i++)
	{
		if( !ChInfo[i].EnCalled ) continue;

		switch(ChInfo[i].InUse)
		{
		case 0:		state="Idle";         break;
		case 1:		state="Off-hook";         break;
		case 2:		state="Dialing";         break;
		case 3:		state="Wait Called Party Answer"; break;
		case 4:		state="Talking";         break;
		}

		m_TrkChList.GetItemText(nIndex,1,tmpstr,50);
		if(state != tmpstr) 
			m_TrkChList.SetItemText(nIndex, 1, state.GetBuffer(50) );

		SsmGetDtmfStr(i, ChInfo[i].DtmfBuf);
		m_TrkChList.GetItemText(nIndex,2,tmpstr,50);
		if(strcmp(ChInfo[i].DtmfBuf,tmpstr) != 0) 
			m_TrkChList.SetItemText(nIndex, 2, ChInfo[i].DtmfBuf);

		nIndex++;
	}
}

void CDialDlg::OnDestroy() 
{
	TerminateThread(hThread, 1);
	CDialog::OnDestroy();
	SsmCloseCti();	
}

int CDialDlg::myGetAnIdleChannel() // find an idle trunk channel
{
	for(int i=0; i<nTotalCh; i++)
	{
		if( !ChInfo[i].InUse && ChInfo[i].EnCalled  ) break;
	}
	
	if(i==nTotalCh) return -1;
	return i;
}

LRESULT CDialDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class

	return CDialog::WindowProc(message, wParam, lParam);
}

DWORD CDialDlg::MyThreadFunction(LPVOID pParam)
{
	
	int  ch,n,AtrkCh;	
	DWORD Param;	
	MESSAGE_INFO EventBuffer;
	CDialDlg *PCDialDlg =(CDialDlg*)pParam;	
	while(1)
	{
    	Sleep(10);
		if(SsmWaitForEvent(50,&EventBuffer)==0)
		{	
			switch(EventBuffer.wEventCode)
			{ 	
				Param=EventBuffer.dwParam;				
		    case E_SYS_TIMEOUT:
				{  
					n=(int)EventBuffer.nReference;
					if(n==PCDialDlg->nTimer)
					{   
						PCDialDlg->DrawUserChState();
						PCDialDlg->DrawTrunkChState();	
					}
				
					
					
				}
				break;
			case  E_CHG_HookState:
				{
				
					ch=EventBuffer.nReference;
				    Param=EventBuffer.dwParam;
					if(Param==0)//station channel hangs up
					{
						OutputDebugString("Station Channel Hangup");
						switch (PCDialDlg->ChInfo[ch].nStep)
						{
						case USER_GET_PHONE_NUM:
							SsmClearRxDtmfBuf(ch);
							PCDialDlg->ChInfo[ch].nStep = USER_IDLE;
							break;
							
						case USER_WAIT_REMOTE_PICKUP: 
							AtrkCh = PCDialDlg->ChInfo[ch].nConnectCh;
							SsmHangup(AtrkCh);
							PCDialDlg->ChInfo[AtrkCh].InUse = 0;
							PCDialDlg->ChInfo[AtrkCh].nStep = TRK_IDLE;
							SsmClearRxDtmfBuf(AtrkCh);
							
							SsmClearRxDtmfBuf(ch);
							PCDialDlg->ChInfo[ch].nStep = USER_IDLE;
							break ;
							
						case USER_TALKING:
							AtrkCh = PCDialDlg->ChInfo[ch].nConnectCh;
							SsmHangup(AtrkCh);
							SsmStopTalkWith(AtrkCh, ch);
							SsmClearRxDtmfBuf(AtrkCh);
							PCDialDlg->ChInfo[AtrkCh].InUse = 0;
							PCDialDlg->ChInfo[AtrkCh].nStep = TRK_IDLE;
							
							PCDialDlg->ChInfo[ch].nStep = USER_IDLE;
							break;
							
						case USER_WAIT_HANGUP:
							SsmStopSendTone(ch);					//stop sending busy tone
							SsmClearRxDtmfBuf(ch);
							PCDialDlg->ChInfo[ch].nStep = USER_IDLE;
							break;
							
						default:
							PCDialDlg->ChInfo[ch].nStep = USER_IDLE;
							break;
						}//end switch
					}
					else if (Param==1)//Station channel Pickup
					{					
						OutputDebugString("Station channel Pickup");
						if (USER_IDLE == PCDialDlg->ChInfo[ch].nStep )
						{				
							strcpy(PCDialDlg->ChInfo[ch].pPhoNumBuf,"");
							SsmClearRxDtmfBuf(ch);					
							PCDialDlg->ChInfo[ch].nStep = USER_GET_PHONE_NUM;
							
						}
						
					}
					
					
				}
				//return 0;
				break;
			case E_CHG_RcvDTMF:
				{   
				    
					ch=EventBuffer.nReference;	
					n=(int)(EventBuffer.dwParam>>16);
					char	str[300];
					wsprintf(str, "Length=%d", n);
					OutputDebugString(str);
					if(PCDialDlg->ChInfo[ch].nStep == USER_GET_PHONE_NUM)
					{
						if(n>=PCDialDlg->m_PhoNumLen)
						{  
							OutputDebugString("4-digit DTMF string received ");
							int m=PCDialDlg->m_PhoNumLen;
							SsmGetDtmfStr(ch,PCDialDlg->ChInfo[ch].pPhoNumBuf);		//retrieve phone num
							PCDialDlg->ChInfo[ch].pPhoNumBuf[m] = '\0';
							if((AtrkCh=PCDialDlg->myGetAnIdleChannel()) == -1)	
							{
								SsmSendTone(ch,1);						// send busy tone	
								PCDialDlg->ChInfo[ch].nStep = USER_WAIT_HANGUP;
							}
							else
							{
								SsmPickup(AtrkCh);
								PCDialDlg->ChInfo[AtrkCh].InUse = 1;					
								
								if ( SsmAutoDial(AtrkCh, PCDialDlg->ChInfo[ch].pPhoNumBuf) ==0)
								{							
									PCDialDlg->ChInfo[AtrkCh].nConnectCh = ch;
									PCDialDlg->ChInfo[AtrkCh].InUse = 2;
									PCDialDlg->ChInfo[AtrkCh].nStep = TRK_AutoDial;
									
									PCDialDlg->ChInfo[ch].nConnectCh = AtrkCh;
									PCDialDlg->ChInfo[ch].nStep = USER_WAIT_REMOTE_PICKUP;
								}
								else 
								{
									SsmHangup(AtrkCh);
									PCDialDlg->ChInfo[AtrkCh].InUse = 0;
									SsmClearRxDtmfBuf(AtrkCh);
									
									SsmSendTone(ch,1);				//send busy tone
									PCDialDlg->ChInfo[ch].nStep = USER_WAIT_HANGUP;
								}
								
							}
						}
						
						
					}
				}
			
				break;
			case E_PROC_AutoDial:
				{
					AtrkCh=(int)EventBuffer.nReference;
					if(PCDialDlg->ChInfo[AtrkCh].nStep == TRK_AutoDial)
					{  
						int temp;
						temp=(int)EventBuffer.dwParam;
						switch(temp)
						{
						case 2: //ringback tone is detected after transmission of calledid 
							PCDialDlg->ChInfo[AtrkCh].InUse = 3;
							break;				
							
						case 5://	silence after ringback tone 
						case 7://	called party answers the call  
							ch = PCDialDlg->ChInfo[AtrkCh].nConnectCh;
							SsmTalkWith(AtrkCh, ch);
							PCDialDlg->ChInfo[AtrkCh].InUse = 4;
							PCDialDlg->ChInfo[AtrkCh].nStep = TRK_TALKING;
							
							PCDialDlg->ChInfo[ch].nStep = USER_TALKING;
							break;
						case 3://no dial tone is detected 
						case 4://called party's line is busy 
						case 6://silence after completin of dial-up 
						case 8://called party answers the call and F1 signal is detected 
						case 9://called party answers the call and F2 signal is detected 
						case 10://the called party does not answer the call. 
						case 11://failed auto-dial
						case 12://unallocated number 
							SsmHangup(AtrkCh);
							PCDialDlg->ChInfo[AtrkCh].InUse = 0;
							SsmClearRxDtmfBuf(AtrkCh);
							PCDialDlg->ChInfo[AtrkCh].nStep = TRK_IDLE;
							
							ch = PCDialDlg->ChInfo[AtrkCh].nConnectCh;
							SsmSendTone(ch,1);					//send busy tone
							PCDialDlg->ChInfo[ch].nStep = USER_WAIT_HANGUP;
							break;
						default:
							break;
						}
					}
				}
				//return 0;
				break;
				
			case E_CHG_ChState:
				{
					Param &=0xFFFF;
					AtrkCh=EventBuffer.nReference;
					if(Param == S_CALL_PENDING)
					{
						SsmHangup(AtrkCh);
						PCDialDlg->ChInfo[AtrkCh].InUse = 0;
						SsmClearRxDtmfBuf(AtrkCh);
						PCDialDlg->ChInfo[AtrkCh].nStep = TRK_IDLE;
						
						ch = PCDialDlg->ChInfo[AtrkCh].nConnectCh;
						SsmSendTone(ch,1);					//send busy tone
						PCDialDlg->ChInfo[ch].nStep = USER_WAIT_HANGUP;	
						
					}
					else if((Param == S_CALL_PENDING)&&(PCDialDlg->ChInfo[AtrkCh].nStep == TRK_TALKING))
					{
						ch = PCDialDlg->ChInfo[AtrkCh].nConnectCh;
						SsmHangup(AtrkCh);
						SsmStopTalkWith(AtrkCh, ch);
						SsmClearRxDtmfBuf(AtrkCh);
						PCDialDlg->ChInfo[AtrkCh].InUse = 0;
						
						SsmSendTone(ch,1);				//send busy tone
						PCDialDlg->ChInfo[ch].nStep = USER_WAIT_HANGUP;
						
					}
					
					
					
				}
				//return 0;
				break;
				
				
				
			default:
				break;
		  }		  
        }
	 }
	 return 0;
}

⌨️ 快捷键说明

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