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

📄 pansrmtcdlg.cpp

📁 基于dialogic语音卡的IVR系统源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PansrMTCDlg.cpp : implementation file
//


#include "stdafx.h"
#include "PansrMTC.h"
#include "PansrMTCDlg.h"
#include "SettingDialog.h"
#include "SimuPhone.h"
#include "process.h"

#include "SourceMonitor.h"
#include "ServiceDataQueue.h"
#include "ServiceBroker.h"

#include "VSInterpreter.h"

extern UINT VSInterpreterThread(LPVOID pParam);


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

/* Defaults for channel parameters
 */
#define DEF_D4XBDNUM 1		/* Default D/4x Board Number to Start use */
#define DEF_DTIBDNUM 1		/* Default DTI Board Number to Start use */
#define DEF_FRONTEND CT_NTANALOG	/* Default network frontend is ANALOG */
#define DEF_SCBUS TRUE		/* Default Bus mode is SCbus */
#define DEF_ROUTEAG FALSE	/* Route analog frontend to resource ??? */
#define DEF_BOARDTAG TRUE	/* Default type is CCM */

#define DEF_MAXCHANS  2     /* Default Number of D/4x Channels to use */

BOOL m_bRunning2=FALSE;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CPansrMTCDlg dialog

CPansrMTCDlg::CPansrMTCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPansrMTCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPansrMTCDlg)
	m_d4xbdnum = 0;
	m_dtibdnum = 0;
	m_maxchans = 0;
	m_scbus = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_state = DLGC_STOPPED_ST;
	if ((ghDLGCEvent = CreateEvent(
		NULL,	// pointer to security attributes, we use default
		FALSE,	// flag for manual reset event, we choose auto-reset
		FALSE,	// flag for initial state, we choose unsignalled
		NULL)	// pointer to event-object name, we choose no name
		) == NULL)// failure
	{
		AfxMessageBox("ghDLGCEvent = CreateEvent failed",
				MB_ICONEXCLAMATION);
    }
	InitDialogic();
	m_maxchans = DEF_MAXCHANS;
	m_d4xbdnum = DEF_D4XBDNUM;
	m_dtibdnum = DEF_DTIBDNUM;
	m_frontend = DEF_FRONTEND;
	
	m_maxchans = GetPrivateProfileInt("CHANNEL", "MAXCHANS", 4, ".\\Setup.ini" );
	m_frontend = GetPrivateProfileInt("CHANNEL", "FRONTEND", 2, ".\\Setup.ini" );
	
	char  faxtype[12] = "";

	GetPrivateProfileString("CHANNEL", "FAXRES", "VFAX",faxtype,12, ".\\Setup.ini" );
	
	if( strcmp( faxtype, "GFAX" ) == 0 ) gammfax  = 1;
	else gammfax = 0;
	
	if( !gammfax )
	{
		faxchans = GetPrivateProfileInt("VFAX", "FAXCHANS", 0, ".\\Setup.ini" );
		faxbdnum = GetPrivateProfileInt("VFAX", "FAXBDNUM", 0, ".\\Setup.ini" );
	}
	else
	{
		faxchans = GetPrivateProfileInt("GFAX", "FAXCHANS", 0, ".\\Setup.ini" );
		faxbdnum = GetPrivateProfileInt("GFAX", "FAXBDNUM", 0, ".\\Setup.ini" );
	}
	
	m_analog = (m_frontend == CT_NTANALOG);
	m_e1 = (m_frontend == CT_NTE1);
	m_t1 = (m_frontend == CT_NTT1);
	m_scbus = DEF_SCBUS;
}


void CPansrMTCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPansrMTCDlg)
	DDX_Control(pDX, ID_SETTING, m_setting);
	DDX_Control(pDX, IDC_DTI, m_static_dti);
	DDX_Control(pDX, IDC_NUM_CHAN, m_static_num_chan);
	DDX_Control(pDX, IDC_FRONTEND, m_static_frontend);
	DDX_Control(pDX, IDC_EDIT_NUM_CHAN, m_edit_num_chan);
	DDX_Control(pDX, IDC_EDIT_DTI, m_edit_dti);
	DDX_Control(pDX, IDC_EDIT_D4x, m_edit_d4x);
	DDX_Control(pDX, IDC_D4X, m_static_d4x);
	DDX_Control(pDX, IDC_CHECK_PEB, m_button_peb);
	DDX_Control(pDX, IDC_DLGC_BUTTON, m_dlgc_button);
	DDX_Text(pDX, IDC_EDIT_D4x, m_d4xbdnum);
	DDV_MinMaxInt(pDX, m_d4xbdnum, 1, 32);
	DDX_Text(pDX, IDC_EDIT_DTI, m_dtibdnum);
	DDV_MinMaxInt(pDX, m_dtibdnum, 1, 32);
	DDX_Text(pDX, IDC_EDIT_NUM_CHAN, m_maxchans);
	DDV_MinMaxInt(pDX, m_maxchans, 1, MAXCHANS); // manually editted
	DDX_Check(pDX, IDC_CHECK_PEB, m_scbus);
	//}}AFX_DATA_MAP
	DDX_Check(pDX, IDC_RADIO_ANALOG, m_analog);
	DDX_Check(pDX, IDC_RADIO_E1, m_e1);
	DDX_Check(pDX, IDC_RADIO_T1, m_t1);
	DDX_Control(pDX, IDC_RADIO_ANALOG, m_button_analog);
	DDX_Control(pDX, IDC_RADIO_E1, m_button_e1);
	DDX_Control(pDX, IDC_RADIO_T1, m_button_t1);
}

BEGIN_MESSAGE_MAP(CPansrMTCDlg, CDialog)
	//{{AFX_MSG_MAP(CPansrMTCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_DLGC_BUTTON, OnDlgcButton)
	ON_WM_CLOSE()
	ON_BN_CLICKED(ID_HELP_INDEX, OnHelpIndex)
	ON_BN_CLICKED(ID_SETTING, OnSetting)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_COMPILE, OnButtonCompile)
	ON_BN_CLICKED(IDC_BUTTON_SIMUPHONE, OnButtonSimuphone)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_RADIO_ANALOG, OnRadioAnalog)
	ON_BN_CLICKED(IDC_RADIO_E1, OnRadioAnalog)
	ON_BN_CLICKED(IDC_RADIO_T1, OnRadioAnalog)
	ON_MESSAGE(WM_DLGC_STOPPED, OnDialogicStopped)
	ON_MESSAGE(WM_DLGC_STATE, OnDialogicState)
	ON_MESSAGE(WM_DLGC_CODE, OnDialogicCode)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPansrMTCDlg message handlers

BOOL CPansrMTCDlg::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);
	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

	SetTimer(1, 60000, NULL);	//延时启动,为自动重启的需要

	GetClientRect(&m_default_client_rect);

	m_dlgc_button.SetWindowText(DLGC_START_STR);

	OnRadioAnalog();

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

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


void CPansrMTCDlg::OnDestroy()
{
  WinHelp(0L, HELP_QUIT);
  CDialog::OnDestroy();
}


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

int RunVSInterpreter(int iMaxChannel)
{
	struct VSInterpreterThreadParam *pvsInterpreter;
	pvsInterpreter = (struct VSInterpreterThreadParam *)malloc(sizeof(VSInterpreterThreadParam));
	
	memset( (char *)pvsInterpreter, 0x0, sizeof(VSInterpreterThreadParam) );
	
	pvsInterpreter->iChannelCount = iMaxChannel;
	strcpy(pvsInterpreter->aszInstructionFileName, VScript);
	AfxBeginThread( VSInterpreterThread,(LPVOID)pvsInterpreter );
	
	Sleep(500);	//等待CONSOLE创建完毕
				
	return 0;
}

void CPansrMTCDlg::OnDlgcButton(void) 
{
	m_bRunning2 = TRUE;

	::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BUTTON_SIMUPHONE), FALSE);

	//显示程序开始运行时间
	time_t ltime;
	time(&ltime);
	HWND hwndEdit_StartTime = ::GetDlgItem(this->m_hWnd, IDC_EDIT_STARTTIME);
	char *szStartTime = ctime(&ltime);
	szStartTime[strlen(szStartTime) - 1] = 0;	//Remove the last char(0x0a)
	::SendMessage(hwndEdit_StartTime, WM_SETTEXT, 0, (LPARAM)szStartTime);


	switch (m_state)
    {
		case DLGC_STARTED_ST:
			
			//XYW modified at 2000/11/27 
			SendMessage(WM_CLOSE);
			
			/*
			m_dlgc_button.EnableWindow(FALSE);
			m_dlgc_button.SetWindowText(DLGC_STOPPING_STR);
			EnableConfiguration(TRUE);
			m_setting.EnableWindow(TRUE);
			if (!SetEvent(ghDLGCEvent)) // unsuccessful
			{
				MessageBox("Set event failed in OnDlgcButton", "error",
					MB_ICONEXCLAMATION);
			}
			*/
			break;

		case DLGC_STOPPED_ST:
			m_setting.EnableWindow(FALSE);
			if (!ResetEvent(ghDLGCEvent)) // make sure ghDLGCEvent is unsignalled
			{
				MessageBox("Reset event failed in OnDlgcButton", "Error",
					MB_ICONEXCLAMATION);
			}
			EnableConfiguration(FALSE); // disable our config buttons
			if (!UpdateData(TRUE)) // load data back into our variables
			{ // must have had a problem with some value.
				EnableConfiguration(TRUE);
			}
			else // data ok
			{ // put data in the args struct so we can send it to Dialogic code				
				m_args.hWnd = m_hWnd;
				m_args.maxchans = m_maxchans;
				m_args.d4xbdnum = m_d4xbdnum;
				m_args.dtibdnum = m_dtibdnum;
				m_args.faxbdnum = faxbdnum;
				m_args.faxchans = faxchans;
				m_args.msibdnum = 0;
				m_args.msichans = 0;

				if (m_analog) m_frontend = CT_NTANALOG;
				else if (m_e1) m_frontend = CT_NTE1;
				else if (m_t1) m_frontend = CT_NTT1;
				else MessageBox("Invalid m_frontend value", "Error", MB_ICONEXCLAMATION);
				m_args.frontend = m_frontend;
				m_args.scbus = m_scbus;
				m_args.routeag = m_scbus;
				m_args.boardtag = DEF_BOARDTAG;

				// provide graphical area to show channels' status
				AddChannelDialogs();

				RunVSInterpreter(m_maxchans);

				if (!AfxBeginThread(RunDialogic,(LPVOID)&m_args))
				{
					MessageBox("AfxBeginThread failed.", "error", MB_ICONEXCLAMATION);
				}
				else
				{

⌨️ 快捷键说明

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