www.pudn.com > TAPI会议系统.rar > tapisampleDlg.cpp


// ---------------------------------------------------------------------------- 
// 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_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(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Blind Transfer" button by transferring a call to the  
// specified address. 
// For this to work, there must be a call active. 
void CTapisampleDlg::OnBlindTransfer()  
{ 
	UpdateData(TRUE); // Get the target address from the edit box 
	if (!m_Address.IsEmpty()) 
	{ 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->BlindTransferCall(m_Address); 
	} 
	else 
		AddText("Error(BlindTransferCall: No Address)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Get Call Status" button by getting the status of the  
// currently active call. 
// For this to work, there must be an active call. 
void CTapisampleDlg::OnGetcallstatus() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->GetCallStatus(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Setup Transfer" button by creating a consultation call. 
// If the actuve call is not already on hold, this will put the call on hold 
// before creating a new call. 
// This requires there to be an active call or a call on hold. 
void CTapisampleDlg::OnSetupTransfer() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetupTransfer(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Dial" button by dialling on the active call. 
// This requires there to be a call active. 
void CTapisampleDlg::OnDial() 
{ 
	UpdateData(TRUE); // Get the number to dial from the edit box 
	if (!m_Address.IsEmpty()) 
	{ 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->Dial(m_Address); 
	} 
	else 
		AddText("Error(lineDial: No Address)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Complete Transfer" button by transferring the held call to 
// the active call. 
// There must be a held call and active call for this to work. 
void CTapisampleDlg::OnCompleteTransfer() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->CompleteTransfer(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Swap Hold" button by swapping the held call and the active 
// call. 
// For this to work, there must be a held call and an active call. 
void CTapisampleDlg::OnSwapHold() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SwapHold(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Park" button by parking the active call. 
// Note that only a directed park will work on IP Office. 
// For this to work there must be an active call and the edit box must contain 
// a park slot id, e.g. 1, 2, 3 or 4. 
void CTapisampleDlg::OnPark() 
{ 
	UpdateData(TRUE); // Get the park id from the edit box 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
	{ 
		if (m_Address.IsEmpty()) 
			line->Park(NULL);		// UNDIRECTED PARK (Doesn't work on IP400) 
		else 
			line->Park(m_Address);	// DIRECTED PARK 
	} 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Unpark" button by retrieving the parked call. 
// For this to work there must be a parked call and the edit box must contain 
// the park id. 
void CTapisampleDlg::OnUnpark() 
{ 
	UpdateData(TRUE); // Get the park id from the edit box 
	if (!m_Address.IsEmpty()) 
	{ 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->Unpark(m_Address);	// Address of park slot (e.g. 1,2,3,4) 
	} 
	else 
		AddText("Error(lineUnpark: No Park Address)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Redirect" button by redirecting a pending call. 
// For this to work there must be a pending call and the edit box should  
// contain the target extension number. 
void CTapisampleDlg::OnRedirect() 
{ 
	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->Redirect(m_Address);	// Target Address 
	} 
	else 
		AddText("Error(lineRedirect: No Target Address)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Add to Conference" button by adding the active call to the 
// held conference. 
// For this to work there must be an active call and a held conference. 
void CTapisampleDlg::OnAddToConference() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->AddToConference(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Remove from Conference" button by removing the last call  
// added to the conference. 
// For this to work there must be an active conference. 
void CTapisampleDlg::OnRemoveFromConference() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->RemoveFromConference(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Address Status" button by displaying the status of the  
// address associated with the selected TAPI line. 
void CTapisampleDlg::OnAddressStatus() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->AddressStatus(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Get Call Info" button by displaying the call info of the  
// active call.  
// For this to work there must be an active call. 
void CTapisampleDlg::OnGetCallInfo() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->GetCallInfo(); 
} 
 
// ---------------------------------------------------------------------------- 
// This function is called when a new controlling extension is selected 
// 
void CTapisampleDlg::OnSelect() 
{ 
	UpdateData(TRUE); // Get the new extension number from the edit box 
 
	// Find the extension in the array of lines, and select the line 
	DWORD extension = atoi(m_Extension); 
	m_Tapi.SetExtension(extension); 
	for (unsigned int i = 0; i < m_Tapi.m_NumDevs; i++) 
	{ 
		if (m_Tapi.m_pLines[i] != NULL) 
		{ 
			if (m_Tapi.m_pLines[i]->m_extension == extension) 
			{ 
				m_Tapi.SetLine(i); 
				CString txt; 
				txt = CString("Extension ") + m_Extension + CString(" selected."); 
				AddText(txt); 
				break; 
			} 
		} 
	} 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Log On" button by logging an extension on  
void CTapisampleDlg::OnLogOn() 
{ 
	UpdateData(TRUE); // Get the new extension number from the edit box 
 
	if (!m_Address.IsEmpty()) 
	{ 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->LogOn(m_Address);	// Log On Id 
	} 
	else 
		AddText("Error(Log On: No Log On Id)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Log Off" button by logging an extension off 
void CTapisampleDlg::OnLogOff() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->LogOff(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Config Dialog" button by displaying the config dialog 
void CTapisampleDlg::OnConfigDialog() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->ConfigDialog(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Divert Destination" button by setting the divert destination 
// For this to work, the edit box must contain the divert destination 
void CTapisampleDlg::OnDivertDestination() 
{ 
	UpdateData(TRUE); // Get the divert destination from the edit box 
 
	if (!m_Address.IsEmpty()) 
	{ 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->DivertDestination(m_Address); 
	} 
	else 
		AddText("Error(Log On: No Divert Destination)"); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Set Divert Settings" button by setting the divert settings 
// The user should set the checkboxes before pressing this button. 
void CTapisampleDlg::OnSetDivertSettings() 
{ 
	UpdateData(TRUE); // Get the values from the divert settings check boxes 
 
	BOOL FwdAll = m_CtlForwardAll.GetCheck(); 
	BOOL FwdBusy = m_CtlForwardBusy.GetCheck(); 
	BOOL FwdNoAnsw = m_CtlForwardNoAnswer.GetCheck(); 
	BOOL DND = m_CtlDoNotDisturb.GetCheck(); 
 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetDivertSettings(FwdAll,FwdBusy,FwdNoAnsw,DND); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Get Divert Settings" button by displaying the divert  
// settings 
void CTapisampleDlg::OnGetDivertSettings() 
{ 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->GetDivertSettings(); 
} 
 
// ---------------------------------------------------------------------------- 
// Respond to the "Set App Specific" button by setting the App Specific data  
// for a call. 
// For this to work their must be a valid call handle in use, e.g. this could 
// be a connected call, held call, etc.  
void CTapisampleDlg::OnSetAppSpecific() 
{ 
	UpdateData(TRUE); // Get the value from the edit box 
 
	if (!m_Address.IsEmpty()) 
	{ 
		DWORD num = atoi(m_Address); 
		TapiLine *line = m_Tapi.GetTapiLine(); 
		if (line) 
			line->SetAppSpecific(num); 
	} 
	else 
		AddText("Error(SetAppSpecific: No number)"); 
} 
 
// ---------------------------------------------------------------------------- 
// This function adds an icon into the TaskBar Notification Area, 
// or Status Area, otherwise known as the system tray. 
void CTapisampleDlg::AddSystemTrayIcon() 
{ 
	NOTIFYICONDATA nda; 
 
	nda.cbSize = sizeof(NOTIFYICONDATA); 
	nda.hWnd = m_hWnd; 
	nda.uID = 1; 
	nda.hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); 
	strcpy(nda.szTip, "IP Office TAPI Sample"); 
	nda.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; 
	nda.uCallbackMessage = WM_USER + 100; // Message Id; 
	Shell_NotifyIcon(NIM_ADD, &nda);  
} 
 
// ---------------------------------------------------------------------------- 
// This function remove the icon from the TaskBar Notification Area. 
void CTapisampleDlg::DeleteSystemTrayIcon() 
{ 
	NOTIFYICONDATA nda; 
 
	nda.cbSize = sizeof(NOTIFYICONDATA); 
	nda.hWnd = m_hWnd; 
	nda.uID = 1; 
	Shell_NotifyIcon(NIM_DELETE, &nda);  
} 
 
// ---------------------------------------------------------------------------- 
// This function responds to the "Hide" button and hides the dialog display. 
// It will reappear when a new call is created, or the user clicks on the icon 
// in the system tray. 
void CTapisampleDlg::OnHide() 
{ 
	ShowWindow(SW_HIDE); 
} 
 
 
// ---------------------------------------------------------------------------- 
// This function displays the dialog when a user clicks on the icon in the  
// system tray. 
LRESULT CTapisampleDlg::OnTrayMessage(WPARAM wParam, LPARAM lParam) 
{ 
	switch (lParam) 
	{ 
	case WM_LBUTTONDOWN: ShowWindow(SW_SHOWNORMAL); break; 
	default: 
		break; 
	} 
	return 0; 
} 
 
void CTapisampleDlg::OnMsgWaitLamp() 
{ 
	UpdateData(TRUE); // Get the value from the edit box 
 
	DWORD num = 0; 
	if (!m_Address.IsEmpty()) 
		num = atoi(m_Address); 
 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetMsgWaitLamp(num); 
} 
 
void CTapisampleDlg::OnInGroup() 
{ 
	UpdateData(TRUE); // Get the value from the edit box 
 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetInGroup(m_Address); 
} 
 
void CTapisampleDlg::OnOutGroup() 
{ 
	UpdateData(TRUE); // Get the value from the edit box 
 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetOutGroup(m_Address); 
} 
 
void CTapisampleDlg::OnSetCallData() 
{ 
	UpdateData(TRUE); // Get the value from the edit box 
 
	TapiLine *line = m_Tapi.GetTapiLine(); 
	if (line) 
		line->SetCallData(m_Address); 
}