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

📄 shr_devent_vcdlg.cpp

📁 三汇CTI示例程序源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SHR_DEvent_VCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "../../../../api/vc6.0/inc/Shpa3api.h" //It's headfile of sanhui
#include "SHR_DEvent_VC.h"
#include "SHR_DEvent_VCDlg.h"

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

DWORD WINAPI ThreadHandleEvent(LPVOID lpParam)
{
	UCHAR pucBuffer[MAX_BUFFERLEN];
	SSM_EVENT SsmEvent;
	char  szErrMsg[400];
	int nretWaitForEvent;
	int nret = 1;
	while(1)
	{
		memset(&SsmEvent, 0, sizeof(SSM_EVENT));
		memset(pucBuffer, 0, sizeof(UCHAR)*MAX_BUFFERLEN);
		SsmEvent.pvBuffer = (PVOID)pucBuffer;
		SsmEvent.dwBufferLength = MAX_BUFFERLEN;
		nretWaitForEvent = SsmWaitForEventA(50, &SsmEvent);
		if(nretWaitForEvent == 0)
		{	
			((CSHR_DEvent_VCDlg*)lpParam)->EventHandler(&SsmEvent);
		}
		else if (nretWaitForEvent == -2)
		{
			SsmGetLastErrMsg(szErrMsg);
			WriteLog(szErrMsg);
			nret = 0;
			break;
		}
	}
	return nret;
}

/////////////////////////////////////////////////////////////////////////////
// CSHR_DEvent_VCDlg dialog

CSHR_DEvent_VCDlg::CSHR_DEvent_VCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSHR_DEvent_VCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSHR_DEvent_VCDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSHR_DEvent_VCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSHR_DEvent_VCDlg)
	DDX_Control(pDX, IDC_RADIO_DEFAULT, m_RdDefault);
	DDX_Control(pDX, IDC_COMBO1, m_CurLine);
	DDX_Control(pDX, IDC_LIST_TRK, m_ListCh);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSHR_DEvent_VCDlg, CDialog)
	//{{AFX_MSG_MAP(CSHR_DEvent_VCDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_RADIO_DEFAULT,		OnRadioDefault)
	ON_BN_CLICKED(IDC_RADIO_A,				OnRadioA)
	ON_BN_CLICKED(IDC_RADIO_MIU,			OnRadioMiu)
	ON_BN_CLICKED(IDC_RADIO_IMA,			OnRadioIma)
	ON_BN_CLICKED(IDC_RADIO_GC8,			OnRadioGc8)
	ON_BN_CLICKED(IDC_RADIO_G729A,			OnRadioG729a)
	ON_BN_CLICKED(IDC_BUTTON_STARTLISTEN,	OnButtonStartlisten)
	ON_BN_CLICKED(IDC_BUTTON_STOPLISTEN,	OnButtonStoplisten)
	ON_NOTIFY(NM_CLICK, IDC_LIST_TRK, OnClickListTrk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSHR_DEvent_VCDlg message handlers
BOOL CSHR_DEvent_VCDlg::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
	BOOL bret = TRUE;
	nRecFormat = -1;
	MaxLine = 0; 
	EVENT_SET_INFO EventSet;							//Event message's structure
	EventSet.dwWorkMode = EVENT_POLLING;				//Windows message mode

	if (!InitCtiSystem())
	{
		bret = FALSE;
	}
	else if(SsmSetEvent(-1,-1,TRUE,&EventSet) == -1)	//Designates event
	{
		SsmGetLastErrMsg(szErrMsg);						//Get wrong message
		AfxMessageBox(szErrMsg, MB_OK, 0);
		WriteLog(szErrMsg);								//Write log file
		bret = FALSE;			   
	}
	else
	{
		ListenChannel = MaxLine;
		InitChannelState();                            //Initialize channel info
		InitUI();									   //Set list info
		SetTimer(10, 100, NULL );
		DWORD dwThreadId;
		CreateThread(NULL, 0, ThreadHandleEvent, this, 0, &dwThreadId);//Create thread to handle event;
	}
	if (!bret)
	{
		PostQuitMessage(0);
	}
	return bret;  // 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 CSHR_DEvent_VCDlg::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 CSHR_DEvent_VCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//Initialize User Interface
void CSHR_DEvent_VCDlg::InitUI()
{
	static int VolumeWidth[10]={80, 90, 90, 85, 70, 230, 98};
    LV_COLUMN lv;
	lv.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
	
	lv.iSubItem = 0;
	lv.pszText = "Channel num";             //"channel num"
	lv.cx = VolumeWidth[0];
	m_ListCh.InsertColumn(0, &lv);

	lv.cx = VolumeWidth[1];
	lv.pszText = "Channel state";			//"channel state"
	lv.iSubItem = 1;
	m_ListCh.InsertColumn(1, &lv);

	lv.cx = VolumeWidth[2];
	lv.pszText = "Listen state";			//"listen state"
	lv.iSubItem = 2;
	m_ListCh.InsertColumn(2, &lv);

	lv.cx = VolumeWidth[3];
	lv.pszText = "Record state";			//"record state"	
	lv.iSubItem = 3;
	m_ListCh.InsertColumn(3, &lv);

	lv.cx = VolumeWidth[4];
	lv.pszText = "Phone num";               //"phone num"
	lv.iSubItem = 4;
	m_ListCh.InsertColumn(4, &lv);

	lv.cx = VolumeWidth[5];
	lv.pszText = "LCD info";				//"lcd info"
	lv.iSubItem = 5;
	m_ListCh.InsertColumn(5, &lv);

	lv.cx = VolumeWidth[6];
	lv.pszText = "Call direction";			//"call direction"
	lv.iSubItem = 6;
	m_ListCh.InsertColumn(6, &lv);
   
    char	ItemIndex[3];
	int		nGetChType;
	for(int i=0; i<MaxLine; i++)
	{
		nGetChType = SsmGetChType(i);					//Obtains designates the channel serial number correspondence the hardware channel type  -1:error
		if(nGetChType == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg);	//Get wrong message
			WriteLog(ChannelState[i].pErrMsg);			//Write log file
		}
		else if(nGetChType == 12)						//Digital telephone record channel
		{
			wsprintf(ItemIndex, "%d", i);
            m_ListCh.InsertItem(i, ItemIndex);
			m_CurLine.InsertString(i,ItemIndex);
		}
	}
	m_CurLine.SetCurSel(0);
	m_RdDefault.SetCheck(BST_CHECKED);
	DWORD dwExtendedStyle = m_ListCh.GetExtendedStyle();
	dwExtendedStyle |= LVS_EX_FULLROWSELECT;
	m_ListCh.SetExtendedStyle(dwExtendedStyle);
	return;
}//InitUI End

//Initialize channel info
void CSHR_DEvent_VCDlg::InitChannelState()
{
	int nGetChType;
	int nChState;
	for(int i=0; i<MaxLine; i++)
	{
		nGetChType = SsmGetChType(i);					//Get channel type
		if(nGetChType == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg);
			WriteLog(ChannelState[i].pErrMsg);
		}
		if(nGetChType == 12)							//Digital telephone record channel  
		{
		    ChannelState[i].WorkState = CH_IDLE;		//Off line state 
			ChannelState[i].IsListen = UNLISTEN;        //Unlisten
            ChannelState[i].IsRecord = UNRECORD;        //Unrecord
			ChannelState[i].pCallId[0] = '\0';			//Phone number is null
		    ChannelState[i].Lcd[0] = '\0';              //LCD info is null
			ChannelState[i].Dir = UNKNOWN ;             //Call direction is "UNKNOWN"
 		}

		nChState = SsmGetChState(i);					//Get the state of current channel. -1:error
		if(nChState == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg);
			WriteLog(ChannelState[i].pErrMsg);
		}
		if(nChState == S_CALL_OFFLINE)							//Off line state
		{
			ChannelState[i].WorkState = CH_OFFLINE;
		}
	}
	return;
}//InitChannelState End


//Initialize system
BOOL CSHR_DEvent_VCDlg::InitCtiSystem()
{
	BOOL bret = TRUE;
	//The set of CTI card configuration filename (*.INI) and memory speech index comparative table filename (*.INI) 
	//        transmits for the driver and the initialize system.
	if(SsmStartCti("ShConfig.ini", "ShIndex.ini") != 0)
	{
		bret = FALSE;
	}


	//SsmGetMaxUsableBoard function,Obtained the driver already to succeed the initialization board card total.
	//SsmGetMaxCfgBoard function,Obtains board card total which in the configuration file configures.
	else if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
	{
		bret = FALSE;
	}

	//Obtains the application program to state in the configuration file passes the magical skill most greatly.
	else if((MaxLine=SsmGetMaxCh()) == -1) 	
	{                                 
		bret = FALSE;;
	}
	if (!bret)
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);
		WriteLog(szErrMsg);
	}
	return bret;
}//InitCtiSystem End


//Update channel info
void CSHR_DEvent_VCDlg::UpdateChannelState()
{
	CString strtemp;
	char getitemtextstr[50];
	int num;								//Line of tag
    int i;
	int nGetChType;
	num=0;

	for(i=0; i<MaxLine; i++)
	{
		nGetChType = SsmGetChType(i);
		if(nGetChType == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg);
			WriteLog(ChannelState[i].pErrMsg);	
		}
		else if(nGetChType == 12)
		{   
			//Channel state
            switch(ChannelState[i].WorkState)
			{
				case CH_IDLE:			strtemp = "Idle";			break;  //"Idle"
				case CH_RING:			strtemp = "Ringing";		break;  //"Ringing"
				case CH_ACTIVE:			strtemp = "Active";			break;  //"Active"
				case CH_OFFLINE:		strtemp = "Offline";		break;  //"Outline"
				case CH_WAITFOR_ONHOOK: strtemp = "WaitforOnhook";	break;	//"WaitforOnhook"
				default:											break;
			}
			m_ListCh.GetItemText(num, 1, getitemtextstr, 29);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 1, strtemp);
            }

			//Listen state
           	switch(ChannelState[i].IsListen)
			{
				case LISTEN:		strtemp = "Listen";		break;	  //"listen"	
				case UNLISTEN:		strtemp = "Unlisten";	break;    //"Unlisten"		
				default:									break;							
			}
			m_ListCh.GetItemText(num, 2, getitemtextstr, 29);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 2, strtemp);
            }

			//Record state
            switch(ChannelState[i].IsRecord)
			{
				case UNRECORD:  strtemp = "Unrecord";	break;	  //"Unrecord"	
				case RECORD:	strtemp = "Record";		break;	  //"Record"
				default:								break;						
			}
			m_ListCh.GetItemText(num, 3, getitemtextstr, 29);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 3, strtemp);
			}

			//Pho Num
			strtemp = "";
			m_ListCh.GetItemText(num, 4, getitemtextstr, 29);
			strtemp.Format("%s", ChannelState[i].pCallId);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 4, strtemp);
			}

			//LCD info
			strtemp = "";
			m_ListCh.GetItemText(num, 5, getitemtextstr, 29);
			strtemp.Format("%s", ChannelState[i].Lcd);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 5, strtemp);
            }

			//Call direction
			switch(ChannelState[i].Dir)
			{
				case UNKNOWN:      strtemp = "Unknown";		break;	  //"Unknown"
				case UP:		   strtemp = "Call out";	break;	  //"Call out"
				case DOWN:		   strtemp = "Call in";		break;	  //"Call in"
				default:									break;					
			}
			m_ListCh.GetItemText(num, 6, getitemtextstr, 29);
			if(getitemtextstr != strtemp)
			{
				m_ListCh.SetItemText(num, 6, strtemp);
            }
			num++;
		}
	}
	return;
}//UpdateChannelState End

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@ EVENT POLLING PROGRAM MODE BASE ON D CHANNEL EVENT  @@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void CSHR_DEvent_VCDlg::EventHandler(PSSM_EVENT pEvent)
{
	DWORD dwCondition = pEvent->dwParam & 0xffff;	//Reason of state transfer; 
	WORD  ch = pEvent->nReference;					//channel number;
	switch(ChannelState[ch].WorkState)				//Judge state
	{
	case CH_IDLE:									//Idle state
		{
			switch(pEvent->wEventCode)				//Judge event
			{
			case E_CHG_ChState:
				{
					if ((pEvent->dwParam & 0xffff) == S_CALL_OFFLINE) //Judge channel state 				 
					{ 
						ChannelState[ch].Dir = UNKNOWN;
						ChannelState[ch].WorkState = CH_OFFLINE;
						ChannelState[ch].Lcd[0] = '\0';
						ClearCallID(pEvent);	//Clear phone number buffer

					}

⌨️ 快捷键说明

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