📄 talkdlg.cpp
字号:
dwError = pCall->GetCallError();
}
switch(wCallState)
{
case IDLE:
m_LineControls[dwLineID].pFrame->m_Colorref = GREEN;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Call");
m_LineControls[dwLineID].pbtnAction->EnableWindow();
DestroyPropSheet(dwLineID, TRUE); // destroy if has calls
// if(1 == m_ctlActiveCalls.GetCount()) // the last one
// {
// m_ctlActiveCalls.ResetContent();
// m_btnDial.EnableWindow(FALSE);
// }
csTemp.Format("line %d", dwLineID);
nNum = m_ctlActiveCalls.FindString(-1, (LPCTSTR) csTemp);
if(nNum != CB_ERR) m_ctlActiveCalls.DeleteString(nNum);
break;
case MAKING:
case PROGRESS:
m_LineControls[dwLineID].pFrame->m_Colorref = PURPLE;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
csTemp.Format("line %d", dwLineID);
nNum = m_ctlActiveCalls.FindString(-1, (LPCTSTR) csTemp);
if(nNum == CB_ERR) nNum = m_ctlActiveCalls.AddString((LPCTSTR) csTemp);
m_ctlActiveCalls.SetCurSel(nNum);
m_btnDial.EnableWindow();
m_LineControls[dwLineID].pbtnAction->EnableWindow();
break;
case OFFERING:
m_LineControls[dwLineID].pFrame->m_Colorref = BROWN;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Pickup");
m_LineControls[dwLineID].pbtnAction->EnableWindow();
if(((CTalkApp *)AfxGetApp())->m_wLineOptions[dwLineID] & AUTOANSWER) //answer immediately
PostMessage(WM_COMMAND, MAKELONG(m_LineControls[dwLineID].uiActionID, BN_CLICKED),
(LPARAM)m_LineControls[dwLineID].pbtnAction->GetSafeHwnd());
break;
case ANSWERING:
m_LineControls[dwLineID].pFrame->m_Colorref = BROWN;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
m_LineControls[dwLineID].pbtnAction->EnableWindow(FALSE);
break;
case CONNECTED:
m_LineControls[dwLineID].pFrame->m_Colorref = YELLOW;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
csTemp.Format("line %d", dwLineID);
nNum = m_ctlActiveCalls.FindString(-1, (LPCTSTR) csTemp);
if(nNum == CB_ERR) nNum = m_ctlActiveCalls.AddString((LPCTSTR) csTemp);
m_ctlActiveCalls.SetCurSel(nNum);
m_btnDial.EnableWindow();
m_LineControls[dwLineID].pbtnAction->EnableWindow();
if(((CTalkApp *)AfxGetApp())->m_wLineOptions[dwLineID] & AUTOPLAY) //play immediately
{
if(!(((CTalkApp *)AfxGetApp())->m_wLineOptions[dwLineID] & PLAY_ONCE)) break;
((CTalkApp *)AfxGetApp())->m_wLineOptions[dwLineID] &= ~PLAY_ONCE;
csTemp.Format("line%d", dwLineID);
csWaveName = AfxGetApp()->GetProfileString((LPCTSTR)csTemp, "WaveFile", "");
if(csWaveName.IsEmpty()) csWaveName = "play.wav";
pCall->Play(csWaveName.GetBuffer(128));
}
break;
case HOLD:
m_LineControls[dwLineID].pFrame->m_Colorref = BLUE;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
m_LineControls[dwLineID].pbtnAction->EnableWindow();
break;
case STOP_MAKING:
case DROPPING:
case DISCONNECTED:
m_LineControls[dwLineID].pFrame->m_Colorref = ORANGE;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
csTemp.Format("line %d", dwLineID);
if(1 == m_ctlActiveCalls.GetCount()) // the last one
{
m_ctlActiveCalls.ResetContent();
m_btnDial.EnableWindow(FALSE);
}
nNum = m_ctlActiveCalls.FindString(-1, (LPCTSTR) csTemp);
if(nNum != CB_ERR) m_ctlActiveCalls.DeleteString(nNum);
break;
default:
break;
}
if(dwError != NULL) // indication that something went wrong
{
m_LineControls[dwLineID].pFrame->m_Colorref = RED;
m_LineControls[dwLineID].pbtnAction->SetWindowText("Hangup");
m_LineControls[dwLineID].pbtnAction->EnableWindow();
}
UpdateData();
m_LineControls[dwLineID].pFrame->Invalidate();
}
void CTalkDlg::DestroyPropSheet(DWORD dwIndex, BOOL bDestroyIfCalls)
{
DWORD i;
// Destroy specific one
if(dwIndex != 0xffffffff)
{
if(m_LineControls[dwIndex].pInfoDlg != NULL)
{
if(bDestroyIfCalls &&
((CInfo *)m_LineControls[dwIndex].pInfoDlg)->m_LineInfo.m_dwCalls == 0)
return;
if(((CInfo *)m_LineControls[dwIndex].pInfoDlg)->m_hWnd &&
((CInfo *)m_LineControls[dwIndex].pInfoDlg)->IsWindowVisible())
((CInfo *)m_LineControls[dwIndex].pInfoDlg)->DestroyWindow();
delete ((CInfo *)m_LineControls[dwIndex].pInfoDlg);
m_LineControls[dwIndex].pInfoDlg = NULL;
}
return;
}
for(i=0; i < m_dwLines; i++)
{
// Destroy prop sheets if any
if(m_LineControls[i].pInfoDlg != NULL)
{
if(bDestroyIfCalls &&
((CInfo *)m_LineControls[i].pInfoDlg)->m_LineInfo.m_dwCalls == 0)
continue;
if(((CInfo *)m_LineControls[i].pInfoDlg)->m_hWnd &&
((CInfo *)m_LineControls[i].pInfoDlg)->IsWindowVisible())
((CInfo *)m_LineControls[i].pInfoDlg)->DestroyWindow();
delete ((CInfo *)m_LineControls[i].pInfoDlg);
m_LineControls[i].pInfoDlg = NULL;
}
}
}
void CTalkDlg::OnDestroy()
{
DWORD i;
// destroy all allocated controls
for(i = 1; i < m_dwLines; i++)
{
if(NULL != m_LineControls[i].pctlLineNum) delete m_LineControls[i].pctlLineNum;
m_LineControls[i].pctlLineNum = NULL;
if(NULL != m_LineControls[i].pFrame) delete m_LineControls[i].pFrame;
m_LineControls[i].pFrame = NULL;
if(NULL != m_LineControls[i].pbtnAction) delete m_LineControls[i].pbtnAction;
m_LineControls[i].pbtnAction = NULL;
if(NULL != m_LineControls[i].pbtnInfo) delete m_LineControls[i].pbtnInfo;
m_LineControls[i].pbtnInfo = NULL;
DestroyPropSheet(); // remove all
}
CDialog::OnDestroy();
}
BOOL CTalkDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
DWORD i;
if(wParam == IDC_TAPIALERT)
{
UpdateDisplayStatus((DWORD) lParam);
return TRUE;
}
WORD wID = LOWORD(wParam);
if((wID < (CONTROL_ARRAY_START + 1)) && wID > IDC_IND0) goto CommandFinish; // not in array
if(!lParam || !wID || HIWORD(wParam) != BN_CLICKED) goto CommandFinish;
for(i=0; i< m_dwLines; i++)
{
if(m_LineControls[i].uiActionID == wID) // Action button clicked
{
OnAction(i);
break;
}
else if(m_LineControls[i].uiInfoID == wID) // Info button clicked
{
OnInfo(i);
break;
}
}
switch(wID) // Handle digits here
{
case IDC_0:
AddDigit("0");
break;
case IDC_1:
AddDigit("1");
break;
case IDC_2:
AddDigit("2");
break;
case IDC_3:
AddDigit("3");
break;
case IDC_4:
AddDigit("4");
break;
case IDC_5:
AddDigit("5");
break;
case IDC_6:
AddDigit("6");
break;
case IDC_7:
AddDigit("7");
break;
case IDC_8:
AddDigit("8");
break;
case IDC_9:
AddDigit("9");
break;
case IDC_POUND:
AddDigit("#");
break;
case IDC_STAR:
AddDigit("*");
break;
default:
break;
}
CommandFinish:
return CDialog::OnCommand(wParam, lParam);
}
void CTalkDlg::AddDigit(LPCSTR lpDigit)
{
if(lpDigit == NULL) // Clear
{
m_csDialString.Empty();
UpdateData(FALSE);
return;
}
if(m_ctlDialString.GetSel())
{
m_ctlDialString.ReplaceSel(lpDigit);
UpdateData(TRUE);
}
else
{
UpdateData(TRUE); // retrieve
m_csDialString += lpDigit;
UpdateData(FALSE); // save
}
}
// If there is a call, try to dial on it
void CTalkDlg::OnDial()
{
int nNum;
DWORD i;
CString csTemp, csTemp1;
LONG lrc;
// first, get the currently selected call
nNum = m_ctlActiveCalls.GetCurSel();
if(nNum == CB_ERR) return;
m_ctlActiveCalls.GetLBText(nNum, csTemp);
for(i=0; i<m_dwLines; i++)
{
csTemp1.Format("line %d", i);
if(!csTemp.Compare((LPCTSTR) csTemp1)) break;
}
if(i >= m_dwLines) i--;
UpdateData();
lrc = m_LineControls[i].pctlLine->ctlLineDial(NULL, (LPCSTR) m_csDialString, 0L); // Country code=0 for now
if(lrc < 0)
{
char szErr[48];
if(!((CTalkApp *)AfxGetApp())->Code2Error(lrc, szErr, 46))
csTemp.Format("Dial on line %d failed reason=%lx", i, lrc);
else
csTemp.Format("Dial on line %d failed reason=%s", i, szErr);
AfxMessageBox(csTemp);
}
}
// Find the pCall using hWave, finish palying on that call.
LONG CTalkDlg::OnWomDone(UINT wParam, LONG lParam)
{
CTapiCall *pCall = (CTapiCall *)(((CTalkApp *)AfxGetApp())->GetCallByParm(KEY_WAVEOUTHANDLE, (DWORD) wParam));
if(pCall != NULL)
{
// For MT implementation, signal the semaphore here
pCall->FinishPlay(wParam, lParam); // override this for MT implementation
}
//::WavexFinishPlay(wParam, lParam);
return TRUE;
}
// End of recording handler
LONG CTalkDlg::OnWimData(UINT wParam, LONG lParam)
{
TRACE("*** TALKER32 ***: WIM_DATA wParam=%lx, lParam=%lx\n", wParam, lParam);
CTapiCall *pCall = (CTapiCall *)(((CTalkApp *)AfxGetApp())->GetCallByParm(KEY_WAVEINHANDLE, (DWORD) wParam));
if(pCall != NULL)
{
// For MT implementation, signal the semaphore here
pCall->FinishRecord(wParam, lParam); // override this for MT implementation
}
//::WavexFinishRecord(wParam, lParam, NULL);
return TRUE;
}
void CTalkDlg::OnCancel()
{
// lineConfigDialog(0, m_hWnd, "tapi/line");
((CTalkApp *)AfxGetApp())->Cleanup();
// may have to wait until all calls are actually closed
CDialog::OnCancel();
}
void CTalkDlg::OnOK()
{
}
void CTalkDlg::OnClear()
{
AddDigit(NULL);
}
void CTalkDlg::OnContextHelp()
{
CDialog::WinHelp(HIDD_TALKER32_DialogMain, HELP_CONTEXT);
}
void CTalkDlg::OnSetFocus(CWnd* pOldWnd)
{
CDialog::OnSetFocus(pOldWnd);
((CTalkApp *)AfxGetApp())->SetHelpId(HIDD_TALKER32_DialogMain);
}
void CTalkDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
((CTalkApp *)AfxGetApp())->SetHelpId(HIDD_TALKER32_DialogMain);
}
/*************************
void CTalkDlg::OnCheck1()
{
CTapiCall *pCall = m_LineControls[0].pctlLine->ctlGetActiveCall();
if(pCall == NULL) return;
if(m_ctlMonitor.GetCheck())
{
LONG lrc = lineMonitorDigits(pCall->m_hCall, LINEDIGITMODE_DTMF);
if(lrc) AfxMessageBox("Monitor failed");
}
else
lineMonitorDigits(pCall->m_hCall,0);
}
void CTalkDlg::OnCheck2()
{
if(m_ctlGather.GetCheck())
{
CTapiCall *pCall = m_LineControls[0].pctlLine->ctlGetActiveCall();
if(pCall == NULL) return;
// LONG lrc = pCall->GatherDigits(20, "*#", 10000, 5000, "");
LPSTR lpDigits = (LPSTR)malloc(2048);
LPSTR lpDelimit = (LPSTR) malloc(16);
lstrcpy(lpDelimit, "*#");
memset(lpDigits, 0, sizeof(lpDigits));
LONG lrc = lineGatherDigits(pCall->m_hCall, LINEDIGITMODE_DTMF, lpDigits,
20, lpDelimit, 8000, 5000);
if(lrc) AfxMessageBox("Gather failed");
}
}
*********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -