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

📄 talker32.cpp

📁 TAPI编程应用
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// talker32.cpp : Defines the class behaviors for the application.
// (c) Dialogic corp 1995, 1996

#include "stdafx.h"
#include <tapi.h>
#include "tapiapp.h"
#include "tapiline.h"
#include "tapicall.h"
#include "talker32.h"
#include "talkdlg.h"
#include "helpid.h"
#include "devspec.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTalkApp

BEGIN_MESSAGE_MAP(CTalkApp, CTapiApp)
	//{{AFX_MSG_MAP(CTalkApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
		ON_COMMAND(ID_HELP, OnHelp)
	//}}AFX_MSG
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTalkApp construction

CTalkApp::CTalkApp()
{
	m_dwTapiAlert = 0;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTalkApp object

CTalkApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTalkApp initialization

BOOL CTalkApp::InitInstance()
{
	DWORD i, dwrc;
	CString csTemp, csAA;

	if(!CTapiApp::InitInstance())	// failed to initialize
		return FALSE;
	
	memset((PBYTE)m_ctlLines, 0, sizeof(m_ctlLines));
	CStatusBox sbDlg;
	sbDlg.m_csStatus = "Initializing TAPI..."; 
	sbDlg.Create(IDD_STATUSDLG);
	if(m_dwLines > MAXLINES) 
	{
		AfxMessageBox("This program supports up to 16 lines", MB_ICONEXCLAMATION);
		m_dwLines = MAXLINES;
	}

	// Read optional info
	memset((LPBYTE)m_wLineOptions, 0, sizeof(m_wLineOptions));
	SetRegistryKey("Dialogic\\SystemRelease 4.x");

	for(i = 0; i < m_dwLines; i++)
	{
		dwrc = 0L;
		if(NULL == (m_ctlLines[i] = new CTapiLine(i))) 	//constructor dn open the line
			MessageBox(NULL, "Failed to get Cline", NULL, MB_OK);
		else dwrc = m_ctlLines[i]->ctlLineOpen(i);
		if(dwrc) 
		{
			char szErr[48];
			if(!Code2Error(dwrc, szErr, 46))
				csTemp.Format("Failed to open line %d reason=%lx", i, dwrc);
			else
				csTemp.Format("Failed to open line %d, reason=%s", i, szErr);
			MessageBox(NULL, (LPCTSTR)csTemp, NULL, MB_ICONSTOP);
		}
		else sbDlg.m_csStatus.Format("Line %d opened", i);
		sbDlg.UpdateData(FALSE); 	  
		csTemp.Format("Line%d", i);
		csAA = GetProfileString((LPCTSTR)csTemp, "AutoAnswer", "");
		if(!csAA.IsEmpty()) 		// Default mode is no autoanswer
		{
			csAA.MakeUpper();
			if((-1 != csAA.Find("YES")) || (-1 != csAA.Find("ON"))) 
			m_wLineOptions[i] |= AUTOANSWER; // set bit 
		}
		csAA = GetProfileString((LPCTSTR)csTemp, "AutoPlay", "");
		if(!csAA.IsEmpty()) 		// Default mode is no autoplay
		{
			csAA.MakeUpper();
			if((-1 != csAA.Find("YES")) || (-1 != csAA.Find("ON"))) 
			m_wLineOptions[i] |= AUTOPLAY; // set bit 
		}
	}	
		
	sbDlg.DestroyWindow();
	CTalkDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with OK
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

// Check for active calls, close them properly; called from the front end before shutting down the app
void CTalkApp::Cleanup()
{
	DWORD i;

	for(i=0; i<m_dwLines; i++)
		m_ctlLines[i]->ctlLineDrop(); 			  
}

// close the lines; if there are active calls shut them
int CTalkApp::ExitInstance() 
{
	DWORD i;
 	
	for(i=0; i<m_dwLines; i++)
	{
		if(m_ctlLines[i]) 			  
			delete m_ctlLines[i];
	}
	return CTapiApp::ExitInstance();
}

// Get CTapiLine by hLine
CTapiLine * CTalkApp::GetLineByHLine(HLINE hLine)
{
	DWORD i;

	for(i=0; i < m_dwLines; i++)
	{
		if(m_ctlLines[i] && m_ctlLines[i]->ctlGetHLine() == hLine) 
		{ 	
			return m_ctlLines[i];
		}
	}
	return NULL;
}

// Get CTapiLine by hcall
CTapiLine * CTalkApp::GetLineByCall(HCALL hCall)
{
	LPLINECALLINFO lpLCI = GetCallInfo(hCall);
	if(lpLCI == NULL) return NULL;	// failed for some reason

	// implement additional logic here to search thru inactive calls
	CTapiLine *pLine = GetLineByHLine(lpLCI->hLine); 
	delete (LPBYTE) lpLCI;
	return pLine;
}

// Find pCall by specified parameter
LPVOID CTalkApp::GetCallByParm(WORD wKey, DWORD dwValue)
{
	DWORD i;
	CTapiCall *pCall;

	for(i=0; i< m_dwLines; i++)
	{
		if(NULL == m_ctlLines[i] || (NULL == (pCall = m_ctlLines[i]->ctlGetActiveCall()))) continue;
		switch(wKey)
		{
			case KEY_LINE:
			 	if(m_ctlLines[i] == (CTapiLine *)dwValue) return (LPVOID)pCall;
				break;

			case KEY_WAVEINHANDLE:
				if(NULL != dwValue && pCall->GetHWaveIn() == dwValue) 
					return (LPVOID)pCall;
				break;

			case KEY_WAVEOUTHANDLE:
				if(NULL != dwValue && pCall->GetHWaveOut() == dwValue) 
					return (LPVOID)pCall;
				break;

			default:
				break;
		}
	}
	return NULL; 	// not found
}

// override of CTapiApp implementation
void CTalkApp::OnLineReply(DWORD dwCallback, DWORD dwRequest, DWORD dwStatus)
{
	// first, find the request
	TRACE("*** TALKER32 *** :enter OnReply ID=%lx Status=%lx\n", dwRequest, dwStatus);
	PASYNCCALL pAC = FindAsyncID(dwRequest, FIND_ID);
	if(pAC == NULL) 	// not found for some reason (???)
	{
		TRACE1("*** TALKER32 *** :Request ID=%lx not found!\n", dwRequest);
		return;
	}	
	ASSERT(pAC->dwID == dwRequest);	 // sanity check

	CTapiLine *pCurLine = (CTapiLine *) pAC->pvLine;
	switch (pAC->wFunction)
	{
		case FUNCTION_MAKECALL:		 
		if(dwStatus & 0x80000000)			 // makecall failed, try to drop 
		{
			TRACE("*** TALKER32 *** :MakeCall ID=%lx failed, err=%lx\n", dwRequest, dwStatus);
			// notify the line, let it find out what to do
		}
		pCurLine->ctlUpdateCallStatus(pAC->wFunction, dwStatus, (CTapiCall *)(pAC->pvCall));
		break;	

		case FUNCTION_DROP:
		if(dwStatus & 0x80000000)			 // drop failed 
			TRACE("*** TALKER32 *** :Drop ID=%lx failed, err=%lx\n", dwRequest, dwStatus);
		// notify the line, let it find out what to do
		pCurLine->ctlUpdateCallStatus(pAC->wFunction, dwStatus, (CTapiCall *)(pAC->pvCall));
		break;	

		case FUNCTION_ANSWER:
		// Answer succeeded?...
		if(dwStatus & 0x80000000)			 // answer failed 
			TRACE("*** TALKER32 *** :Answer ID=%lx failed, err=%lx\n", dwRequest, dwStatus);
		pCurLine->ctlUpdateCallStatus(pAC->wFunction, dwStatus, (CTapiCall *)(pAC->pvCall));
		break;	

		case FUNCTION_DIAL:
		if(dwStatus & 0x80000000)			 // answer failed 
			TRACE("*** TALKER32 *** :Dial ID=%lx failed, err=%lx\n", dwRequest, dwStatus);
		pCurLine->ctlUpdateCallStatus(pAC->wFunction, dwStatus, (CTapiCall *)(pAC->pvCall));
		break;	

		case FUNCTION_DEVSPEC:				 // device specific...
		if(dwStatus & 0x80000000)			 
			TRACE("*** TALKER32 *** :Devspec ID=%lx failed, err=%lx\n", dwRequest, dwStatus);
		pCurLine->ctlUpdateCallStatus(pAC->wFunction, dwStatus, (CTapiCall *)(pAC->pvCall));
		break;	

		default:
		TRACE("*** TALKER32 ***: Undefined async function call\n"); 
		break;	
	} // end of switch(wFunction)
	TRACE("*** TALKER32 *** :exit OnReply ID=%lx\n", dwRequest);
		
	FindAsyncID(dwRequest, REMOVE_ID);	// Done, remove the ID from list
}

// Override of CTapiApp OnLineCallInfo implementation
void CTalkApp::OnLineCallInfo(HCALL hCall, DWORD dwCallBack, DWORD dwParm)
{
	BOOL brc, bFound = FALSE;
	DWORD i;

	LPLINECALLINFO lpCI = GetCallInfo(hCall);
	TRACE("*** TALKER32 *** :OnLineCallinfo hCall=%lx, DevID=%d\n", 
		hCall, lpCI->dwLineDeviceID);
	if(lpCI == NULL) return;
	for(i=0; i < m_dwLines; i++)
	{
		if(m_ctlLines[i] && m_ctlLines[i]->ctlGetHLine() == lpCI->hLine) 
		{ 	
			bFound = TRUE;
			break;
		}
	}
	if(bFound) brc = m_ctlLines[i]->ctlUpdateCallInfo(hCall, lpCI); 
	if(!bFound || (bFound && brc == FALSE)) delete lpCI;
}

// Override of CTapiApp OnCallState implementation
void CTalkApp::OnCallState(HCALL hCall, DWORD hCallback, DWORD dwCallState,
							DWORD dwCallStateDetail, DWORD dwCallPrivilege)
{
	// May issue lineGetCallStatus here to get info
	CString csTemp;
	DWORD dwDiscMode;
	LONG lrc;

	TRACE("*** TALKER32 *** :OnLineCallState hCall=%lx, state=%lx, detail=%lx\n",
		 hCall, dwCallState, dwCallStateDetail);
	CTapiLine *pclTemp = GetLineByCall(hCall);
	if(pclTemp == NULL) 		// line not found
	{
		TRACE("*** TALKER32 ***: OnCallState failed to find line\n");
		return;

⌨️ 快捷键说明

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