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

📄 fsk_event_vcdlg.cpp

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

#include "stdafx.h"
#include "FSK_Event_VC.h"
#include "FSK_Event_VCDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFSK_Event_VCDlg dialog

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

void CFSK_Event_VCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFSK_Event_VCDlg)
	DDX_Control(pDX, IDC_LIST, m_ChList);
	DDX_Radio(pDX, IDC_RADIO_I, m_nRcvFSKMode);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFSK_Event_VCDlg, CDialog)
	//{{AFX_MSG_MAP(CFSK_Event_VCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_AUTO_DIAL, OnButtonAutoDial)
	ON_BN_CLICKED(IDC_BUTTON_TEST, OnButtonTest)
	ON_BN_CLICKED(IDC_RADIO_I, OnRadioI)
	ON_BN_CLICKED(IDC_RADIO_II, OnRadioIi)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFSK_Event_VCDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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(!InitCtiBoard())		
	{
		PostQuitMessage(0);
		return FALSE;
	}

	//Set event-driven mode
	EVENT_SET_INFO EventSet;		
	EventSet.dwWorkMode = EVENT_MESSAGE;	
	EventSet.lpHandlerParam = this->GetSafeHwnd();	
	if(SsmSetEvent(-1, -1, TRUE, &EventSet) == -1)
		MessageBox("Fail to call SsmSetEvent");

	SetDlgItemInt(IDC_EDIT_SEND_CH, 0);
	SetDlgItemInt(IDC_EDIT_RCV_CH, 2);
	SetDlgItemInt(IDC_EDIT_PHO_NUM, 222);

	InitChListCtrl();		//Initialize list
	UpdateChListCtrl();		//Update list	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFSK_Event_VCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CFSK_Event_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 CFSK_Event_VCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


BOOL CFSK_Event_VCDlg::InitCtiBoard()
{
	char szCurPath[MAX_PATH];		//Current path
	char szShIndex[MAX_PATH];		//Path to ShIndex.ini
	char szShConfig[MAX_PATH];		//Path to ShConfig.ini
	CString CErrMsg;			    //Error message
	GetCurrentDirectory(MAX_PATH, szCurPath);
	strcpy(szShIndex, szCurPath);
	strcpy(szShConfig, szCurPath);
	strcat(szShIndex, "\\ShIndex.ini");
	strcat(szShConfig, "\\ShConfig.ini");
	
	//Load configuration file and initialize system
	if(SsmStartCti(szShConfig, szShIndex) == -1)
	{
		SsmGetLastErrMsg(CErrMsg.GetBuffer(300));//Get error message
		AfxMessageBox(CErrMsg, MB_OK);
		CErrMsg.ReleaseBuffer();
		return FALSE;
	}
	
	//Judge if the number of initialized boards is the same as
	//	   that of boards specified in the configuration file
	if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
	{
		SsmGetLastErrMsg(CErrMsg.GetBuffer(300)); //Get error message	
		AfxMessageBox(CErrMsg, MB_OK);
		CErrMsg.ReleaseBuffer();
		return FALSE;
	}
	//Get the maximum number of the channels
	nMaxCh = SsmGetMaxCh();	  
	if(nMaxCh == -1)
	{
		MessageBox("Fail to call SsmGetMaxCh");
		return FALSE;
	}
	
	for(int i = 0; i < nMaxCh; i++)
	{
		ChInfo[i].nSelfFlag = 0;
		ChInfo[i].nIndex = 0;
		ChInfo[i].nLinkToCh = -1;
		memset(ChInfo[i].szDTMF, 0, sizeof(char)*100);
		memset(ChInfo[i].szPhoNum, 0, sizeof(char)*20);
		
		ChInfo[i].nChType = SsmGetChType(i);
		switch(ChInfo[i].nChType)
		{
		case 0: 
		case 4:
		case 6:
		case 7:
		case 8:
		case 11:
			ChInfo[i].nChState = TRK_IDLE;
			break;
		case 1:
		case 2:
			ChInfo[i].nChState = USER_IDLE;
			break;
		}
	}

	
	return TRUE;
}


void CFSK_Event_VCDlg::InitChListCtrl()
{
	static int ColumnWidth[4] = {40, 150, 200, 410};
 	LV_COLUMN lvc;
	lvc.mask =  LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;

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

	lvc.iSubItem = 1;
	lvc.pszText = "ChannelType";
	lvc.cx = ColumnWidth[1];
	m_ChList.InsertColumn(1, &lvc);

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

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

	char dig[3];
	for(int i = 0; i < nMaxCh; i++)
	{
		switch(ChInfo[i].nChType)
		{
		case 0:
		case 1:
		case 2:
		case 4:
		case 6:
		case 7:
		case 8:
		case 11:
			m_ChList.InsertItem(i, _itoa(i, dig, 10));
			break;
		}
	}
}


void CFSK_Event_VCDlg::UpdateChListCtrl()
{
	char szNewStat[100];
	char szOldStat[100];
	int nIndex = 0;

	for(int i = 0; i < nMaxCh; i++)
	{
		switch(ChInfo[i].nChType)
		{
		case 0:
		case 1:
		case 2:
		case 4:
		case 6:
		case 7:
		case 8:
		case 11:
			//Display channel type
			switch(ChInfo[i].nChType)
			{
			case 0:			strcpy(szNewStat, "Analog trunk channel");					break;
			case 1:			strcpy(szNewStat, "Station channel");						break;
			case 2:			strcpy(szNewStat, "Station channel");						break;
			case 4:			strcpy(szNewStat, "Digital channel (SS1)");					break;
			case 6:			strcpy(szNewStat, "Digital channel (SS7 TUP)");				break;
			case 7:			strcpy(szNewStat, "Digital channel (ISDN user side)");		break;
			case 8:			strcpy(szNewStat, "Digital channel (ISDN network side)");	break;
			case 11:		strcpy(szNewStat, "Digital channel (SS7 ISUP)");			break;		
			}
			m_ChList.GetItemText(nIndex, 1, szOldStat, 10);
			if(strcmp(szOldStat, szNewStat) != 0)
			{
				m_ChList.SetItemText(nIndex, 1, szNewStat);
			}
			//Display channel state
			switch(ChInfo[i].nChState)
			{
			case TRK_IDLE:          strcpy(szNewStat, "Idle");				break;				
			case TRK_CHECK_DIAL:	strcpy(szNewStat, "Dialing…");			break;
			case TRK_TALKING:		strcpy(szNewStat, "Talking…");			break;
			case TRK_CHECK_RCV:		strcpy(szNewStat, "Receiving FSK…");	break;
			case TRK_CHECK_SEND:	strcpy(szNewStat, "Sending FSK…");		break;
			case TRK_PICKUP:		strcpy(szNewStat, "Pickup");			break;
			case TRK_CHK_SEND:		strcpy(szNewStat, "Sending FSK…");		break;
			case TRK_USER_RCV_END:	strcpy(szNewStat, "End of receiving");	break;
			case USER_IDLE:			strcpy(szNewStat, "Idle");				break;
			case USER_CHK_RCV:		strcpy(szNewStat, "Receiving…");		break;
			case USER_WAIT_HANGUP:	strcpy(szNewStat, "Wait for hangup");	break;
			}
			m_ChList.GetItemText(nIndex, 2, szOldStat, 10);
			if(strcmp(szOldStat, szNewStat) != 0)
			{
				m_ChList.SetItemText(nIndex, 2, szNewStat);
			}
			//Display received DTMF
			m_ChList.GetItemText(nIndex, 3, szOldStat, 20);
			if(strcmp(szOldStat, ChInfo[i].szDTMF) != 0)
			{
				m_ChList.SetItemText(nIndex, 3, ChInfo[i].szDTMF);
			}

			nIndex++;
			break;
		}
	}
}


LRESULT CFSK_Event_VCDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	int nCh;
	int nDataLen;
	char cNewDtmf;
	char szBuf[260];
	char *szTemp;

⌨️ 快捷键说明

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