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

📄 recdemodlg.cpp

📁 上海维卡的事件驱动模式示例
💻 CPP
字号:
// RecDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RecDemo.h"
#include "RecDemoDlg.h"
#include "TvcDrvApi.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()

/////////////////////////////////////////////////////////////////////////////
// CRecDemoDlg dialog

CRecDemoDlg::CRecDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRecDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRecDemoDlg)
		// 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 CRecDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRecDemoDlg)
	DDX_Control(pDX, IDC_LIST2, m_wndLogList);
	DDX_Control(pDX, IDC_LIST1, m_wndChList);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CRecDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CRecDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRecDemoDlg message handlers

BOOL CRecDemoDlg::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
	
	
	m_wndChList.SetExtendedStyle(m_wndChList.GetExtendedStyle() | LVS_EX_FULLROWSELECT
						|LVS_SORTASCENDING|LVS_TYPEMASK);

	m_wndChList.InsertColumn(0,"序号",		LVCFMT_RIGHT,	40);
	m_wndChList.InsertColumn(1,"状态",	LVCFMT_LEFT,	80);
	m_wndChList.InsertColumn(2,"本机号码",	LVCFMT_LEFT,	80);
	m_wndChList.InsertColumn(3,"对方号码",	LVCFMT_LEFT,	80);

	m_wndLogList.SetExtendedStyle(m_wndLogList.GetExtendedStyle() | LVS_EX_FULLROWSELECT
						|LVS_SORTASCENDING|LVS_TYPEMASK);

	m_wndLogList.InsertColumn(1,"记录",	LVCFMT_LEFT,400);
	if(TvcLoadDrvA()!=0)
	{
		TvcGetLastErrMsg(szMsg,256);
		AfxMessageBox(szMsg);
		return false;
	}
	int nMaxCh=TvcGetTotalCh();
	nTotalCh = 0;
	for(int i=0;i<nMaxCh;i++)
	{
		int nType = TvcGetChType(i);
		if(	nType == ANALOG_REC ||
			nType == DIGITAL_ISDNU ||
			nType == DIGITAL_SS7TUP ||
			nType == DIGITAL_SS1 )
			nTotalCh ++;
	} //统计录音的数量

	pChInfo = new CHINFO[nTotalCh];
	ZeroMemory(pChInfo,nTotalCh* sizeof(CHINFO));
	int nIndex =0 ;
	CHINFO *pCh; 
	for(i=0;i<nMaxCh;i++)
	{
		
		int nType = TvcGetChType(i);
		if(	nType == ANALOG_REC ||
			nType == DIGITAL_ISDNU ||
			nType == DIGITAL_SS7TUP ||
			nType == DIGITAL_SS1 )
		{
			sprintf(szMsg,"%d",nIndex);
			m_wndChList.InsertItem(nIndex,szMsg);
			pCh = pChInfo+nIndex;
			pCh->nIndex = nIndex;  //
			pCh->nIdxInHard = i;
			pCh->nChState = -1;
			nIndex ++;
			TvcSetPreRecordPara(pCh->nIdxInHard,tvc_voc_alaw,7,1000);//每个通道开启一个1000ms的预录音缓冲
			TvcSetRecAgc(pCh->nIdxInHard,1); //开启自动增益
			//还可以做一个其它设置
		}
	}
	SetTimer(100,200,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CRecDemoDlg::OnTimer(UINT nIDEvent) 
{
	if(nIDEvent==100)
	{
		CHINFO *pCh;
		int nState;
		CString szStr;
		SYSTEMTIME t;
		for(int i = 0 ;i< nTotalCh ;i++)
		{
			pCh = pChInfo + i;
			nState =TvcGetChState(pCh->nIdxInHard);
			if(nState!=pCh->nChState)
			{
				//通道状态变化了
				switch(nState)
				{
				case ch_empty://断线是特殊情况
				case ch_free:
					m_wndChList.SetItemText(pCh->nIndex,3,"");
					m_wndChList.SetItemText(pCh->nIndex,2,"");
					if(nState==ch_empty)
						m_wndChList.SetItemText(pCh->nIndex,1,"断线");
					else
						m_wndChList.SetItemText(pCh->nIndex,1,"空闲");

					if(TvcCheckRecord(pCh->nIdxInHard)==0)
						break;//原来没有录音
					TvcStopRecord(pCh->nIdxInHard);
 					szStr.Format("Ch%d %s 本机=%s 对方=%s File=%s",
						pCh->nIdxInHard, pCh->nIsCallOut>0?"打出":"打入", pCh->szLocalCode,pCh->szRemoteCode,pCh->szFileName);
					m_wndLogList.InsertItem(0,szStr);
					ZeroMemory(pCh->szFileName,32);
					if(TvcGetChType(pCh->nIdxInHard)!=ANALOG_REC)
						ZeroMemory(pCh->szLocalCode,32);	//模拟卡的本机号码一般是系统设置的
					ZeroMemory(pCh->szRemoteCode,64);
					break;
				case ch_talking:
					GetLocalTime(&t);
					sprintf(pCh->szFileName,".\\%03d_%04d%02d%02d%02d%02d%2d.wav",
						pCh->nIdxInHard,t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute,t.wSecond);
					pCh->nIsCallOut = TvcGetCallDirection(pCh->nIdxInHard);
					if(TvcGetChType(pCh->nIdxInHard)==ANALOG_REC)
					{ //模拟只能取到主叫
						if(!pCh->nIsCallOut)
						{
							//呼入
							TvcGetCallerId(pCh->nIdxInHard,pCh->szRemoteCode,32);
//							m_wndChList.SetItemText(pCh->nIndex,2,pCh->szRemoteCode);
						}
					}
					else
					{
						if(pCh->nIsCallOut)
						{//数字线呼叫时,主叫号码是本机号码,被叫号码是对方号码
							TvcGetCallerId(pCh->nIdxInHard,pCh->szLocalCode,32);
							TvcGetCallerId(pCh->nIdxInHard,pCh->szRemoteCode,33);
						}
						else
						{
							TvcGetCallerId(pCh->nIdxInHard,pCh->szRemoteCode,32);
							TvcGetCallerId(pCh->nIdxInHard,pCh->szLocalCode,33);
						}
					}
					TvcStartFileRecordEx(pCh->nIdxInHard,pCh->szFileName,"",tvc_voc_alaw,0,0,0,plyrec_always);
					m_wndChList.SetItemText(pCh->nIndex,3,pCh->szRemoteCode);
					m_wndChList.SetItemText(pCh->nIndex,2,pCh->szLocalCode);
					m_wndChList.SetItemText(pCh->nIndex,1,"录音");
					break;
				case ch_ringing:
					m_wndChList.SetItemText(pCh->nIndex,1,"振铃");
					break;
				case ch_wait_talk:
					m_wndChList.SetItemText(pCh->nIndex,1,"外拨中"); // 这个状只有数字卡录音时才有
					break;
				}
				pCh->nChState = nState;
			}
			if(pCh->nChState == ch_talking)
			{
				UCHAR szDtmf[32];
				int nRet=TvcGetDtmfStr(pCh->nIdxInHard,szDtmf,32,1);
				if(nRet>0)
				{
					//模拟卡打出时的DTMF就是对方号码,其它情况要不要记录dtmf,根据需要做就可以了
					if(pCh->nIsCallOut && TvcGetChType(pCh->nIdxInHard)== ANALOG_REC)
					{
						if(nRet + strlen(pCh->szRemoteCode)<32)
							strcat(pCh->szRemoteCode,(PCHAR)szDtmf); //
						m_wndChList.SetItemText(pCh->nIndex,3,pCh->szRemoteCode);
					}

				}
			}
			
		}
	}
	
	CDialog::OnTimer(nIDEvent);
}

void CRecDemoDlg::OnButton1() 
{
	CRecDemoDlg::OnCancel();
	
}

⌨️ 快捷键说明

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