📄 tapiwavedrivertestdlg.cpp
字号:
// TAPIWaveDriverTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include <tapi.h>
#include "TAPILine.h"
#include "TAPIWaveDriverTest.h"
#include "TAPIWaveDriverTestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define RECORD_DURATION 5 //.25
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CTAPIWaveDriverTestDlg dialog
CTAPIWaveDriverTestDlg::CTAPIWaveDriverTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTAPIWaveDriverTestDlg::IDD, pParent),
m_Wave(this),
m_DTMF(this)
{
//{{AFX_DATA_INIT(CTAPIWaveDriverTestDlg)
m_InfoTextBox = _T("");
m_ebCallText = _T("");
m_strWaveFile = _T("");
m_strDialTones = _T("");
m_strLine = _T("601");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_WaveDeviceID = WAVE_MAPPER;
m_SoundDeviceID = WAVE_MAPPER;
m_bRecording = false;
m_bDigitMonitoringOn = false;
m_strDialTones = _T("123A456B789C*0#D");
m_bufcount = 0;
}
void CTAPIWaveDriverTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTAPIWaveDriverTestDlg)
DDX_Control(pDX, IDC_BUTTON_MONDIGITS, m_MonitorDigits);
DDX_Control(pDX, IDC_BUTTON_STOP, m_StopButton);
DDX_Control(pDX, IDC_BUTTON_RECORD, m_RecordButton);
DDX_Control(pDX, IDC_BUTTON_BROWSW, m_BrowseButton);
DDX_Control(pDX, IDC_BUTTON_SENDWAV, m_SendButton);
DDX_Text(pDX, IDC_EDIT_INFO, m_InfoTextBox);
DDV_MaxChars(pDX, m_InfoTextBox, 30000);
DDX_Text(pDX, IDC_EDIT_CALL, m_ebCallText);
DDX_Text(pDX, IDC_EDIT_WAVEFILE, m_strWaveFile);
DDX_Text(pDX, IDC_EDIT_TONES, m_strDialTones);
DDX_Text(pDX, IDC_EDIT_LINE, m_strLine);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTAPIWaveDriverTestDlg, CDialog)
//{{AFX_MSG_MAP(CTAPIWaveDriverTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_MAKECALL, OnButtonMakecall)
ON_BN_CLICKED(IDC_BUTTON_ANSWER, OnButtonAnswer)
ON_BN_CLICKED(IDC_BUTTON_HANGUP, OnButtonHangup)
ON_BN_CLICKED(IDC_BUTTON_SENDWAV, OnButtonSendWAV)
ON_BN_CLICKED(IDC_BUTTON_BROWSW, OnButtonBrowseWAV)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_BN_CLICKED(IDC_BUTTON_RECORD, OnButtonRecord)
ON_BN_CLICKED(IDC_BUTTON_TONES, OnButtonTones)
ON_BN_CLICKED(IDC_BUTTON_TEST1, OnButtonTest1)
ON_BN_CLICKED(IDC_BUTTON_MONITORTONE, OnButtonMonitortone)
ON_BN_CLICKED(IDC_BUTTON_GENDIGITS, OnButtonGendigits)
ON_BN_CLICKED(IDC_BUTTON_MONDIGITS, OnButtonMondigits)
ON_BN_CLICKED(IDC_BUTTON_SELECTLINE, OnButtonSelectline)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTAPIWaveDriverTestDlg message handlers
//*************************************************************************
BOOL CTAPIWaveDriverTestDlg::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
SetWindowText("TAPI 2.x and Wave Driver Test");
m_TAPIConnection.InitialiseTAPI(this);
m_TAPIConnection.OpenValidLines();
SetExtensionField();
CheckButtons();
// Get device id of Wave Driver
UINT no_of_devs = waveOutGetNumDevs();
if (no_of_devs > 0)
{
for (UINT id=0; id<no_of_devs; id++)
{
WAVEOUTCAPS WaveOutCaps;
if (waveOutGetDevCaps( id, &WaveOutCaps, sizeof(WaveOutCaps)) == MMSYSERR_NOERROR)
{
if (strncmp(WaveOutCaps.szPname, "IP Office WIDWOD", 16) == 0)
{
this->m_WaveDeviceID = id;
// Initiate the Wave Driver by sending a tone regardless of
// any TAPI connection.
// This ensures that lineGenerateTone works first time.
m_DTMF = "1";
m_DTMF.Dial(m_WaveDeviceID, 100, 1);
// break;
}
else
{
// Get soundcard
// WAVEFORMATEX waveFormat;
// if (waveOutOpen(0, id, &waveFormat, 0, 0L,
// WAVE_FORMAT_QUERY | (id == WAVE_MAPPER ? 0 : WAVE_MAPPED)) == MMSYSERR_NOERROR)
// {
// m_SoundDeviceID = id;
// }
}
}
}
}
// return false;
return TRUE; // return TRUE unless you set the focus to a control
}
//*************************************************************************
void CTAPIWaveDriverTestDlg::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 CTAPIWaveDriverTestDlg::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 CTAPIWaveDriverTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//*************************************************************************
// Add a line of text to the output box
// This function is used by all the event response functions to allow the
// user to view the information they generate.
// The function will clear the text box when it gets too full.
void CTAPIWaveDriverTestDlg::AddText(LPCTSTR pszNewText)
{
UpdateData(TRUE); // In case the user has typed something in an edit box
if (m_InfoTextBox.GetLength() + strlen(pszNewText) > 25000)
m_InfoTextBox.Empty();
m_InfoTextBox += pszNewText;
m_InfoTextBox += _T("\r\n");
UpdateData(FALSE); // Update the text box
}
//*************************************************************************
void CTAPIWaveDriverTestDlg::OnDestroy()
{
CDialog::OnDestroy();
m_TAPIConnection.ShutdownTAPI();
}
//*************************************************************************
// Clunky method to trap user messages for now.
LRESULT CTAPIWaveDriverTestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_USER_TAPI_INFO)
{
AddText(m_TAPIConnection.GetLastMessage());
}
else if (message == WM_USER_TAPI_STATUS)
{
CheckButtons();
}
return CDialog::WindowProc(message, wParam, lParam);
}
//*************************************************************************
void CTAPIWaveDriverTestDlg::OnButtonMakecall()
{
// Attempt to make a call.
UpdateData(TRUE); // In case the user has typed something in an edit box
if (m_ebCallText.GetLength() > 0)
{
CString info;
info.Format("Calling %s", m_ebCallText);
AddText(info);
TAPILine *pTAPILine = m_TAPIConnection.GetTapiLine();
if (pTAPILine)
{
pTAPILine->MakeCall(m_ebCallText);
}
}
else
{
AfxMessageBox("No extension number entered.");
}
}
//*************************************************************************
void CTAPIWaveDriverTestDlg::OnButtonAnswer()
{
TAPILine *pTAPILine = m_TAPIConnection.GetTapiLine();
if (pTAPILine)
{
pTAPILine->AnswerCall();
}
}
//*************************************************************************
void CTAPIWaveDriverTestDlg::OnButtonHangup()
{
TAPILine *pTAPILine = m_TAPIConnection.GetTapiLine();
if (pTAPILine)
{
pTAPILine->HangUp();
}
}
//*************************************************************************
// Work out which buttons can be enabled
void CTAPIWaveDriverTestDlg::CheckButtons()
{
// Get the current status of our controlled Dn from the TAPI classes
BOOL bActive = FALSE;
BOOL bWaiting = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -