// PhoneDlg.cpp : implementation file
//
// This is a part of the TAPI Applications Classes C++ library.
// Original Copyright � 1995-2004 JulMar Entertainment Technology, Inc. All rights reserved.
//
// "This program is free software; you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program; if not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Or, contact: JulMar Technology, Inc. at: info@julmar.com."
//
#include "stdafx.h"
#include "Phone.h"
#include "PhoneDlg.h"
#include "CallDataDlg.h"
#include "UUIDlg.h"
#include "DialDlg.h"
#include "AgentStateDlg.h"
#include "ConfListDlg.h"
#include "TransferDlg.h"
#include "CompleteTransferDlg.h"
#include "CompleteCall.h"
#include "SetupConfDlg.h"
#include "PhoneCapsDlg.h"
#include "PredDialDlg.h"
#include "ISDNInfo.h"
#include "QOSInfo.h"
#include "ForwardDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Globals
CMainApp theApp;
DWORD g_dwLastError = 0;
const UINT IDT_TIMER = 100;
/////////////////////////////////////////////////////////////////////////////
// CMyLine
//
// Override of the CTapiLine for notifications
//
class CMyLine : public CTapiLine
{
DECLARE_DYNCREATE (CMyLine)
protected:
virtual void OnAddressStateChange (DWORD dwAddressID, DWORD dwState) {
CTapiLine::OnAddressStateChange (dwAddressID, dwState);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_ADDRESSCHANGE, (WPARAM)GetAddress(dwAddressID));
}
virtual void OnAgentStateChange (DWORD dwAddressID, DWORD dwFields, DWORD dwState) {
CTapiLine::OnAgentStateChange (dwAddressID, dwFields, dwState);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_AGENTCHANGE, (WPARAM)GetAddress(dwAddressID), dwFields);
}
virtual void OnDeviceStateChange (DWORD dwDeviceState, DWORD dwStateDetail1, DWORD dwStateDetail2) {
CTapiLine::OnDeviceStateChange(dwDeviceState, dwStateDetail1, dwStateDetail2);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_LINECHANGE, (WPARAM)this);
}
virtual void OnNewCall (CTapiCall* pCall) {
CTapiLine::OnNewCall(pCall);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_NEWCALL, (WPARAM)pCall);
}
};
/////////////////////////////////////////////////////////////////////////////
// CMyCall
//
// Override of the CTapiCall for notifications
//
class CMyCall : public CTapiCall
{
DECLARE_DYNCREATE (CMyCall)
public:
virtual void OnInfoChange (DWORD dwInfoState) {
CTapiCall::OnInfoChange(dwInfoState);
CWnd* pwnd = theApp.m_pMainWnd;
if (pwnd != NULL && IsWindow(pwnd->GetSafeHwnd()))
{
if (dwInfoState & LINECALLINFOSTATE_USERUSERINFO)
pwnd->PostMessage(UM_FLASHWINDOW, IDC_USERUSERINFO);
if (dwInfoState & (LINECALLINFOSTATE_HIGHLEVELCOMP | LINECALLINFOSTATE_LOWLEVELCOMP | LINECALLINFOSTATE_CHARGINGINFO))
pwnd->PostMessage(UM_FLASHWINDOW, IDC_ISDNINFO);
if (dwInfoState & LINECALLINFOSTATE_QOS)
pwnd->PostMessage(UM_FLASHWINDOW, IDC_QOS);
if (dwInfoState & LINECALLINFOSTATE_CALLDATA)
pwnd->PostMessage(UM_FLASHWINDOW, IDC_CALLDATA);
((CPhoneDlg*)pwnd)->SendMessage(UM_CALLCHANGE, (WPARAM)this);
}
}
virtual void OnStateChange (DWORD dwState, DWORD dwStateDetail, DWORD dwPrivilage) {
CTapiCall::OnStateChange(dwState, dwStateDetail, dwPrivilage);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_CALLCHANGE, (WPARAM)this);
}
virtual void OnMediaModeChange (DWORD dwMediaMode) {
CTapiCall::OnMediaModeChange(dwMediaMode);
((CPhoneDlg*)theApp.m_pMainWnd)->SendMessage(UM_CALLCHANGE, (WPARAM)this);
}
};
IMPLEMENT_DYNCREATE (CMyLine, CTapiLine)
IMPLEMENT_DYNCREATE (CMyCall, CTapiCall)
IMPLEMENT_DYNCREATE (CMyPhone, CTapiPhone)
/////////////////////////////////////////////////////////////////////////////
// CMainApp::InitInstance
//
// Initialize the main application
//
BOOL CMainApp::InitInstance()
{
#if _MSC_VER < 1300
// Enable 3d controls
Enable3dControlsStatic();
#endif
// Initialize a connection with TAPI and determine if there
// are any TAPI complient devices installed.
if (GetTAPIConnection()->Init("JPhoneDialer",
RUNTIME_CLASS(CMyLine), NULL, RUNTIME_CLASS(CMyCall),
RUNTIME_CLASS(CMyPhone)) != 0 ||
GetTAPIConnection()->GetLineDeviceCount() == 0)
{
AfxMessageBox ("There are no TAPI devices installed!");
return FALSE;
}
// Create our dialog.
CPhoneDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
return FALSE;
}// CMainApp::InitInstance
/////////////////////////////////////////////////////////////////////////////
// Message maps (required by MFC)
//
BEGIN_MESSAGE_MAP(CPhoneDlg, CDialog)
//{{AFX_MSG_MAP(CPhoneDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELCHANGE(IDC_LINES, OnChangeLine)
ON_BN_CLICKED(IDC_STARTSESSION, OnStartSession)
ON_NOTIFY(UDN_DELTAPOS, IDC_SESSIONSPIN, OnDeltaposSession)
ON_CBN_SELCHANGE(IDC_ADDRESS, OnAddressChange)
ON_NOTIFY(UDN_DELTAPOS, IDC_CALLSPIN, OnChangeCall)
ON_MESSAGE(UM_CALLCHANGE, i_OnCallChange)
ON_MESSAGE(UM_NEWCALL, i_OnNewCall)
ON_MESSAGE(UM_ADDRESSCHANGE, i_OnAddressChange)
ON_MESSAGE(UM_LINECHANGE, i_OnLineChange)
ON_MESSAGE(UM_AGENTCHANGE, i_OnAgentChange)
ON_MESSAGE(UM_FLASHWINDOW, OnFlashWindow)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_DROP, OnDropCall)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_ACCEPT, OnAcceptCall)
ON_BN_CLICKED(IDC_ANSWER, OnAnswerCall)
ON_BN_CLICKED(IDC_MAKECALL, OnMakeCall)
ON_BN_CLICKED(IDC_HOLD, OnHoldCall)
ON_BN_CLICKED(IDC_SWAPHOLD, OnSwapHoldCall)
ON_BN_CLICKED(IDC_CALLDATA, OnCallData)
ON_BN_CLICKED(IDC_USERUSERINFO, OnUserUserInfo)
ON_BN_CLICKED(IDC_DIAL, OnDial)
ON_BN_CLICKED(IDC_REDIRECT, OnRedirectCall)
ON_BN_CLICKED(IDC_UNPARK, OnUnparkCall)
ON_BN_CLICKED(IDC_PICKUP, OnPickupCall)
ON_BN_CLICKED(IDC_CONNECTED, OnChangeLineStatus)
ON_BN_CLICKED(IDC_AGENTINFO, OnAgentInfo)
ON_BN_CLICKED(IDC_CONFLIST, OnConferenceList)
ON_BN_CLICKED(IDC_TRANSFER, OnTransfer)
ON_BN_CLICKED(IDC_PARK, OnParkCall)
ON_BN_CLICKED(IDC_COMPLETE, OnCompleteTransfer)
ON_BN_CLICKED(IDC_COMPLETECALL, OnCompleteCall)
ON_BN_CLICKED(IDC_SETUPCONF, OnSetupConference)
ON_BN_CLICKED(IDC_ADDTOCONF, OnAddToConference)
ON_BN_CLICKED(IDC_REMOVEFROMCONF, OnRemoveFromConference)
ON_BN_CLICKED(IDC_PHONEINFO, OnPhoneInfo)
ON_BN_CLICKED(IDC_CONFIG, OnConfig)
ON_WM_CLOSE()
ON_EN_CHANGE(IDC_PHONENUMBER, OnAddressChange)
ON_BN_CLICKED(IDC_INSERVICE, OnChangeLineStatus)
ON_BN_CLICKED(IDC_MESSAGEWAITING, OnChangeLineStatus)
ON_BN_CLICKED(IDC_LOCKED, OnChangeLineStatus)
ON_BN_CLICKED(IDC_ISDNINFO, OnISDN)
ON_BN_CLICKED(IDC_QOS, OnQos)
ON_BN_CLICKED(IDC_FORWARD, OnForward)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LookupError
//
// Return a string representing a TAPI error
//
LPCSTR LookupError(LONG lResult)
{
static char szBuff[1024];
if (lResult == 0xffffffff)
strcpy (szBuff, "Request timeout");
else if (lResult > 0x80000000)
{
if (lResult >= 0x80000000 && lResult < 0x90000000)
{
lResult &= ~0x80000000;
lResult |= 0x8000;
}
else
{
lResult &= ~0x90000000;
lResult |= 0x9000;
}
if (LoadString(AfxGetResourceHandle(), (UINT) lResult, szBuff, 1024) == 0)
strc