📄 sampldlg.cpp
字号:
// SamplDlg.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h" // replace with theApp header if needed
#include "SamplDlg.h"
#include "opentsrv.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog
CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSampleDlg)
m_DeviceID = _T("");
m_ToDeviceID = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_TsapiWndPtr = 0;
}
CSampleDlg::~CSampleDlg()
{
// delete the hidden TSAPI window
if(m_TsapiWndPtr)
{
delete m_TsapiWndPtr;
}
}
// For non-MFC folks, this is a helper routine for passing data back-and-forth
// from this class to the dialog.
void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSampleDlg)
DDX_Control(pDX, IDC_ANSWER, m_AnswerControl);
DDX_Control(pDX, IDC_HOLD, m_HoldControl);
DDX_Control(pDX, IDC_HANGUP, m_HangUpControl);
DDX_Control(pDX, IDC_CALLLIST, m_CallListControl);
DDX_Control(pDX, IDC_CALL, m_CallControl);
DDX_Text(pDX, IDC_DEVICEID, m_DeviceID);
DDX_Text(pDX, IDC_TODEVICEID, m_ToDeviceID);
DDV_MaxChars(pDX, m_ToDeviceID, 64);
//}}AFX_DATA_MAP
}
// For non-MFC folks, this map replaces the large "switch" statement found in
// straight C Windows programs. The ON_MESSAGE() lines were added manually.
// Read them as "when a message of type {first argument} is received, call
// the method {second argument}"
BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
ON_MESSAGE(WM_TSAPIFAILURE, OnTsapiFailure)
ON_MESSAGE(WM_TSAPIACSUNSOLICITED, OnTsapiAcsUnsolicited)
ON_MESSAGE(WM_TSAPICSTACONFIRMATION, OnTsapiCstaConfirmation)
ON_MESSAGE(WM_TSAPICSTAUNSOLICITED, OnTsapiCstaUnsolicited)
//{{AFX_MSG_MAP(CSampleDlg)
ON_BN_CLICKED(IDC_CALL, OnCall)
ON_BN_CLICKED(IDC_HANGUP, OnHangup)
ON_EN_CHANGE(IDC_TODEVICEID, OnChangeTodeviceid)
ON_WM_TIMER()
ON_NOTIFY(NM_CLICK, IDC_CALLLIST, OnClickCalllist)
ON_BN_CLICKED(IDC_HOLD, OnHold)
ON_BN_CLICKED(IDC_ANSWER, OnAnswer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers
BOOL CSampleDlg::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
// init the call list control
m_CallListControl.InsertColumn(0, "Device ID", LVCFMT_LEFT, 90, 0);
m_CallListControl.InsertColumn(LOCAL_CONNECTION_STATE, "Local Connection State",
LVCFMT_LEFT, 150, LOCAL_CONNECTION_STATE);
m_CallListControl.InsertColumn(REMOTE_CONNECTION_STATE, "Remote Connection State",
LVCFMT_LEFT, 150, REMOTE_CONNECTION_STATE);
// setting a timer allows the dialog to be displayed before initialization is
// completed - the init will be completed when the timer fires.
if(!SetTimer(1, 1, NULL))
{
// if the timer can't be set, just call the OnTimer() method manually so
// initialization can complete.
OnTimer(1);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CSampleDlg::OnTimer(UINT nIDEvent)
{
// finish initialization...
// ok to kill the timer even if it wasn't active (i.e. in the failure case from
// OnInitDialog().
KillTimer(nIDEvent);
// the class that calls COpenTsrv's DoModal() method is responsible
// for the CTsapiWnd object that will be created. It will be this
// classes responsibility to handle CTsapiWnd memory clean-up (delete
// the CTsapiWnd object) and also this classes responsibility to decide
// what to do on failures of the TSAPI stream.
COpenTsrv openDlg;
openDlg.m_TsapiController = (CWnd*)this;
if(openDlg.DoModal() != IDOK)
{
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// retrieve the specified device to be monitored and the hidden TSAPI window
m_DeviceID = openDlg.m_DeviceID;
m_TsapiWndPtr = openDlg.m_TsapiWndPtr;
// retrieve a pointer to the device record in the hidden TSAPI window
DeviceID_t deviceID;
lstrcpy(deviceID, m_DeviceID);
CTsapiDevice* pTsapi = m_TsapiWndPtr->GetDeviceRecord(deviceID);
if(!pTsapi)
{
AfxMessageBox("device record not found");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// Notify the TSAPI window that all events for this device should be forwarded
// to this dialog
// Note that this is different than the m_TsapiController - which handles generic
// memory clean-up and TSAPI stream failures. SetWndPtr() is device-specific. If
// the app handled more than 1 device, they could have the same or different
// windows handling their events.
pTsapi->SetWndPtr(this);
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
// this method is called when the Call button is pressed
void CSampleDlg::OnCall()
{
// retrieve the data out of the dialog
UpdateData(TRUE);
// retrieve the device record for the monitored device
DeviceID_t deviceID;
lstrcpy(deviceID, m_DeviceID);
CTsapiDevice* pTsapi = m_TsapiWndPtr->GetDeviceRecord(deviceID);
if(!pTsapi)
{
AfxMessageBox("device record not found");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// make a call from monitored device to the "to device"
// use the device record pointer as the invoke ID
RetCode_t rc = cstaMakeCall(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t)pTsapi, (DeviceID_t*)&deviceID,
(DeviceID_t*)(LPCTSTR)m_ToDeviceID, NULL);
if(rc < 0)
{
AfxMessageBox("make call failed");
return;
}
return;
}
// this method is called when the Hang Up button is pressed
void CSampleDlg::OnHangup()
{
// retrieve the data out of the dialog
UpdateData(TRUE);
// retrieve the device record for the monitored device
DeviceID_t deviceID;
lstrcpy(deviceID, m_DeviceID);
CTsapiDevice* pTsapi = m_TsapiWndPtr->GetDeviceRecord(deviceID);
if(!pTsapi)
{
AfxMessageBox("device record not found");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// get selected list item
LV_ITEM lvItem;
lvItem.iItem = m_CallListControl.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
m_CallListControl.GetItem(&lvItem);
// retrieve the connection ID for this call that is associated with
// the monitored device - this is the "local" connection
ConnectionID_t connID;
if(!pTsapi->GetLocalConnection(lvItem.lParam, connID))
{
AfxMessageBox("no active call found");
return;
}
// clear the connection
// use the device record pointer as the invoke ID
RetCode_t rc = cstaClearConnection(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t)pTsapi,
&connID, NULL);
if(rc < 0)
{
AfxMessageBox("clear connection failed");
return;
}
// disable hang-up and hold buttons
m_HangUpControl.EnableWindow(FALSE);
m_HoldControl.EnableWindow(FALSE);
return;
}
// this method is called when the Answer button is pressed
void CSampleDlg::OnAnswer()
{
// retrieve the data out of the dialog
UpdateData(TRUE);
// retrieve the device record for the monitored device
DeviceID_t deviceID;
lstrcpy(deviceID, m_DeviceID);
CTsapiDevice* pTsapi = m_TsapiWndPtr->GetDeviceRecord(deviceID);
if(!pTsapi)
{
AfxMessageBox("device record not found");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// get selected list item
LV_ITEM lvItem;
lvItem.iItem = m_CallListControl.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
m_CallListControl.GetItem(&lvItem);
// retrieve the connection ID for this call that is associated with
// the monitored device - this is the "local" connection
ConnectionID_t connID;
if(!pTsapi->GetLocalConnection(lvItem.lParam, connID))
{
AfxMessageBox("no active call found");
return;
}
// answer the call
// use the device record pointer as the invoke ID
RetCode_t rc = cstaAnswerCall(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t)pTsapi,
&connID, NULL);
if(rc < 0)
{
AfxMessageBox("answer call failed");
return;
}
// disable the answer button
m_AnswerControl.EnableWindow(FALSE);
return;
}
// this method is called when the Hold button is pressed
void CSampleDlg::OnHold()
{
// retrieve the data out of the dialog
UpdateData(TRUE);
// retrieve the device record for the monitored device
DeviceID_t deviceID;
lstrcpy(deviceID, m_DeviceID);
CTsapiDevice* pTsapi = m_TsapiWndPtr->GetDeviceRecord(deviceID);
if(!pTsapi)
{
AfxMessageBox("device record not found");
PostMessage(WM_COMMAND, IDCANCEL, 0);
return;
}
// get selected list item
LV_ITEM lvItem;
lvItem.iItem = m_CallListControl.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
m_CallListControl.GetItem(&lvItem);
// retrieve the connection ID for this call that is associated with
// the monitored device - this is the "local" connection
ConnectionID_t connID;
if(!pTsapi->GetLocalConnection(lvItem.lParam, connID))
{
AfxMessageBox("no active call found");
return;
}
// get the local connection state out of selected list control item
CString connState = m_CallListControl.GetItemText(lvItem.iItem, LOCAL_CONNECTION_STATE);
// If the local connection state is Held, then retrieve the call that
// is being held
// else, put the call on hold
// Note: the text of the hold button could also have been looked at
// to decide whether to hold or retrieve the call (if text == H&old,
// then hold the call, else retrieve the call).
if(connState == _T("Held"))
{
// retrieve held call
// use the device record pointer as the invoke ID
RetCode_t rc = cstaRetrieveCall(m_TsapiWndPtr->m_AcsHandle, (InvokeID_t)pTsapi,
&connID, NULL);
if(rc < 0)
{
AfxMessageBox("retrieve call failed");
return;
}
// now that the call has been retrieved, change button text
m_HoldControl.SetWindowText(_T("H&old"));
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -