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

📄 tapisampledlg.cpp

📁 基于TAPI 2.0的软电话源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ----------------------------------------------------------------------------
// IP Office SDK (c) Avaya 2001. All rights reserved.
//
// PROJECT:  TapiSample
// FILE:     tapisampleDlg.cpp
// CREATED:  Geoff Froud, based on previous work by Carl Muller
//
// See tapisample.h for an explanation of this program.
//
// This is the implementation file for the dialog class.
// See tapisampleDlg.h for the definition of this class
//
// ----------------------------------------------------------------------------


#include "stdafx.h"
#include "tapisample.h"
#include "tapisampleDlg.h"
#include "splash.h"

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

#define TRAYMSG		WM_USER + 100

// ============================================================================
// 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()
};

// ----------------------------------------------------------------------------
// Constructor for the about box
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

// ----------------------------------------------------------------------------
// Support transferring information between the Windows structures
// and the about box member variables
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

// ----------------------------------------------------------------------------
// Message map for the about box
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// ----------------------------------------------------------------------------
// CTapisampleDlg dialog
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Constructor for the dialog box
#pragma warning (disable : 4355)
CTapisampleDlg::CTapisampleDlg(CWnd* pParent /*=NULL*/) :
	CDialog(CTapisampleDlg::IDD, pParent),
	m_Tapi(*this)
#pragma warning (default : 4355)
{

	//{{AFX_DATA_INIT(CTapisampleDlg)
	m_TextBox = _T("");
	m_Address = _T("");
	m_Extension = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

// ----------------------------------------------------------------------------
// Destructor for the dialog box
CTapisampleDlg::~CTapisampleDlg()
{
}

BOOL CTapisampleDlg::PreTranslateMessage(MSG* pMsg) 
{
	if (CSplashWnd::PreTranslateAppMessage(pMsg))
		return TRUE; 	

	return CDialog::PreTranslateMessage(pMsg);
}

// ----------------------------------------------------------------------------
// 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 CTapisampleDlg::AddText(LPCTSTR pszNewText)
{
	UpdateData(TRUE); // In case the user has typed something in an edit box
	if (m_TextBox.GetLength() + strlen(pszNewText) > 30000)
		m_TextBox.Empty();
	m_TextBox += pszNewText;
	m_TextBox += _T("\r\n");
	UpdateData(FALSE); // Update the text box
}

// ----------------------------------------------------------------------------
// Set the current extension
void CTapisampleDlg::SetExtension(LPCTSTR pszNewExtension)
{
	UpdateData(TRUE); // In case the user has typed something in an edit box
	m_Extension = pszNewExtension;
	UpdateData(FALSE); // Update the box
}

// ----------------------------------------------------------------------------
// Support data exchange between member variables and windows structures
void CTapisampleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTapisampleDlg)
	DDX_Control(pDX, IDC_CONFERENCECALL, m_CtlConferenceCall);
	DDX_Control(pDX, IDC_ANSWERCALL, m_CtlAnswerCall);
	DDX_Control(pDX, IDC_DROPCALL, m_CtlDropCall);
	DDX_Control(pDX, IDC_HOLDCALL, m_CtlHoldCall);
	DDX_Control(pDX, IDC_MAKECALL, m_CtlMakeCall);
	DDX_Control(pDX, IDC_UNHOLDCALL, m_CtlUnholdCall);
	DDX_Control(pDX, IDC_BLINDTRANSFER, m_CtlBlindTransferCall);
	DDX_Control(pDX, IDC_SETUPTRANSFER, m_CtlSetupTransfer);
	DDX_Control(pDX, IDC_DIAL, m_CtlDial);
	DDX_Control(pDX, IDC_COMPLETETRANSFER, m_CtlCompleteTransfer);
	DDX_Control(pDX, IDC_SWAPHOLD, m_CtlSwapHold);
	DDX_Control(pDX, IDC_PARK, m_CtlPark);
	DDX_Control(pDX, IDC_UNPARK, m_CtlUnpark);
	DDX_Control(pDX, IDC_REDIRECT, m_CtlRedirect);
	DDX_Control(pDX, IDC_ADDTOCONFERENCE, m_CtlAddToConference);
	DDX_Control(pDX, IDC_REMOVEFROMCONFERENCE, m_CtlRemoveFromConference);
	DDX_Control(pDX, IDC_GETCALLINFO, m_CtlGetCallInfo);
	DDX_Control(pDX, IDC_FWDALLCHECK, m_CtlForwardAll);
	DDX_Control(pDX, IDC_FWDBUSYCHECK, m_CtlForwardBusy);
	DDX_Control(pDX, IDC_FWDNOANSWCHECK, m_CtlForwardNoAnswer);
	DDX_Control(pDX, IDC_DNDCHECK, m_CtlDoNotDisturb);
	DDX_Text(pDX, IDC_TEXTBOX, m_TextBox);
	DDX_Text(pDX, IDC_ADDRESS, m_Address);
	DDX_Text(pDX, IDC_EXTENSION, m_Extension);
	//}}AFX_DATA_MAP
}

// ----------------------------------------------------------------------------
// Message map for the dialog box
BEGIN_MESSAGE_MAP(CTapisampleDlg, CDialog)
	//{{AFX_MSG_MAP(CTapisampleDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_CLEARTEXT, OnCleartext)
	ON_BN_CLICKED(IDC_DROPCALL, OnDropcall)
	ON_BN_CLICKED(IDC_MAKECALL, OnMakecall)
	ON_BN_CLICKED(IDC_HOLDCALL, OnHoldcall)
	ON_BN_CLICKED(IDC_UNHOLDCALL, OnUnholdcall)
	ON_BN_CLICKED(IDC_CONFERENCECALL, OnConferencecall)
	ON_BN_CLICKED(IDC_BLINDTRANSFER, OnBlindTransfer)
	ON_BN_CLICKED(IDC_ANSWERCALL, OnAnswercall)
	ON_BN_CLICKED(IDC_GETCALLSTATUS, OnGetcallstatus)
	ON_BN_CLICKED(IDC_SETUPTRANSFER, OnSetupTransfer)
	ON_BN_CLICKED(IDC_DIAL, OnDial)
	ON_BN_CLICKED(IDC_COMPLETETRANSFER, OnCompleteTransfer)
	ON_BN_CLICKED(IDC_SWAPHOLD, OnSwapHold)
	ON_BN_CLICKED(IDC_PARK, OnPark)
	ON_BN_CLICKED(IDC_UNPARK, OnUnpark)
	ON_BN_CLICKED(IDC_REDIRECT, OnRedirect)
	ON_BN_CLICKED(IDC_ADDTOCONFERENCE, OnAddToConference)
	ON_BN_CLICKED(IDC_REMOVEFROMCONFERENCE, OnRemoveFromConference)
	ON_BN_CLICKED(IDC_GETADDRSTATUS, OnAddressStatus)
	ON_BN_CLICKED(IDC_GETCALLINFO, OnGetCallInfo)
	ON_BN_CLICKED(IDC_SELECTBUTTON, OnSelect)
	ON_BN_CLICKED(IDC_LOGON, OnLogOn)
	ON_BN_CLICKED(IDC_LOGOFF, OnLogOff)
	ON_BN_CLICKED(IDC_CONFIGDIALOG, OnConfigDialog)
	ON_BN_CLICKED(IDC_DIVERTDEST, OnDivertDestination)
	ON_BN_CLICKED(IDC_SETDIVERTSETTINGS, OnSetDivertSettings)
	ON_BN_CLICKED(IDC_GETDIVERTSETTINGS, OnGetDivertSettings)
	ON_BN_CLICKED(IDC_SETAPPSPECIFIC, OnSetAppSpecific)
	ON_BN_CLICKED(IDC_HIDE, OnHide)
	ON_BN_CLICKED(IDC_MSGWAITLAMP, OnMsgWaitLamp)
	ON_BN_CLICKED(IDC_INGROUP, OnInGroup)
	ON_BN_CLICKED(IDC_OUTGROUP, OnOutGroup)
	ON_BN_CLICKED(IDC_SETCALLDATA, OnSetCallData)
	ON_BN_CLICKED(IDC_LISTEN, OnListen)
	ON_BN_CLICKED(IDC_INTRUDE, OnIntrude)
	ON_BN_CLICKED(IDC_ENABLEBUTTONS, OnEnableButtons)
	ON_BN_CLICKED(IDC_RESET, OnReset)
	ON_BN_CLICKED(IDC_ACCCODEBUTTON, OnAccountCode)
	ON_BN_CLICKED(IDC_GENDIGBUTTON, OnGenerateDigits)
	ON_MESSAGE(TRAYMSG, OnTrayMessage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// ----------------------------------------------------------------------------
// CTapisampleDlg message handlers
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Handle initialising the dialog box
BOOL CTapisampleDlg::OnInitDialog()
{
	// In third party mode, this application takes a while to start up, so
	// show a splash screen
	CSplashWnd::EnableSplashScreen(TRUE);
    CSplashWnd::ShowSplashScreen(this);

	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_Tapi.InitialiseTAPI();
	m_Tapi.OpenValidLines();

	AddSystemTrayIcon();

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


// ----------------------------------------------------------------------------
// Handle commands from the system menu of the dialog box
void CTapisampleDlg::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 CTapisampleDlg::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();
	}
}

// ----------------------------------------------------------------------------
// Get ready to close the dialog box
void CTapisampleDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	m_Tapi.ShutdownTAPI();

	DeleteSystemTrayIcon();
}

// ----------------------------------------------------------------------------
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTapisampleDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// ----------------------------------------------------------------------------
// Work out which buttons can be enabled
void CTapisampleDlg::CheckButtons()
{
	// Get the current status of our controlled Dn from the TAPI classes
	BOOL bActive = FALSE;
	BOOL bWaiting = FALSE;
	BOOL bHeld = FALSE;
	BOOL bPending = FALSE;
	BOOL bConsulting = FALSE;
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
	{
		bActive = !!(line->m_hConnectedCall);
		bWaiting = !!(line->m_hWaitingCall);
		bHeld = !!(line->m_hHeldCall);
		bPending = !!(line->m_hPendingCall);
		bConsulting = !!(line->m_hConsultationCall);
	}

	// Enable only the appropriate buttons
	m_CtlConferenceCall.EnableWindow(bActive && bHeld);
	m_CtlAnswerCall.EnableWindow(bPending);
	m_CtlDropCall.EnableWindow(bActive || bWaiting);
	m_CtlHoldCall.EnableWindow(bActive);
	m_CtlMakeCall.EnableWindow(!bActive && !bPending);
	m_CtlUnholdCall.EnableWindow(bHeld);
	m_CtlBlindTransferCall.EnableWindow(bActive);
	m_CtlSetupTransfer.EnableWindow(bActive);
	m_CtlDial.EnableWindow(bConsulting);
	m_CtlCompleteTransfer.EnableWindow(bActive && bHeld);
	m_CtlSwapHold.EnableWindow(bActive && bHeld);
	m_CtlPark.EnableWindow(bActive);
	m_CtlUnpark.EnableWindow(TRUE);
	m_CtlRedirect.EnableWindow(bPending);
	m_CtlAddToConference.EnableWindow(bActive && bHeld);
	m_CtlRemoveFromConference.EnableWindow(bActive);
	m_CtlGetCallInfo.EnableWindow(bActive || bWaiting || bHeld || bPending || bConsulting);
}

// ----------------------------------------------------------------------------
// Respond to user interaction
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Respond to the "Clear Display" button by clearing the text box
void CTapisampleDlg::OnCleartext() 
{
	UpdateData(TRUE); // In case the user has typed something in an edit box
	m_TextBox = _T("");
	UpdateData(FALSE); // Update the text box
}


// ----------------------------------------------------------------------------
// Respond to the "Make Call" button by making a call to the specified address
// For this to work, there must not be a call active.
// There can be a call on hold though.
// There must be a number in the target edit box.
void CTapisampleDlg::OnMakecall() 
{
	UpdateData(TRUE); // In case the user has typed something in an edit box
	if (!m_Address.IsEmpty())
	{
		TapiLine *line = m_Tapi.GetTapiLine();
		if (line)
			line->MakeCall(m_Address);
	}
	else
		AddText("Error(MakeCall: No Address)");
}

// ----------------------------------------------------------------------------
// Cancel a call, in response to the user clicking the "Cancel Call" button
// For this to work, there must be a call in progress
void CTapisampleDlg::OnDropcall() 
{
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
		line->DropCall();
}

// ----------------------------------------------------------------------------
// Respond to the "Answer Call" button by answering a call
// For this to work, there must be a call pending.
void CTapisampleDlg::OnAnswercall() 
{
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
		line->AnswerCall();
}

// ----------------------------------------------------------------------------
// Respond to the "Hold Call" button by holding a call
// For this to work, there must be a call active
void CTapisampleDlg::OnHoldcall() 
{
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
		line->HoldCall();
}

// ----------------------------------------------------------------------------
// Respond to the "Unhold Call" button by retrieving a call
// For this to work, there must be a call on hold and no call active
void CTapisampleDlg::OnUnholdcall() 
{
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
		line->UnholdCall();
}

// ----------------------------------------------------------------------------
// Respond to the "Conference Call" button by starting a conference
// For this to work, there must be a call on hold and a call active.
void CTapisampleDlg::OnConferencecall() 
{
	TapiLine *line = m_Tapi.GetTapiLine();
	if (line)
		line->ConferenceCall();
}

// ----------------------------------------------------------------------------

⌨️ 快捷键说明

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