// DLG_UBox_Dial.cpp : 实现文件 // #include "stdafx.h" #include "CorpSms.h" #include "DLG_UBox_Dial.h" #include "afxdialogex.h" #include "DLG_UBox_Setup.h" #include "MainFrm.h" #include "FUboxLog.h" // DLG_UBox_Dial 对话框 IMPLEMENT_DYNAMIC(DLG_UBox_Dial, CDialogEx) DLG_UBox_Dial::DLG_UBox_Dial(CWnd* pParent /*=NULL*/) : CDialogEx(DLG_UBox_Dial::IDD, pParent) { m_strNumber = _T(""); m_pMainFrame = NULL; m_bCalling =false; m_bShowLog = false; } DLG_UBox_Dial::~DLG_UBox_Dial() { } void DLG_UBox_Dial::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); // DDX_Control(pDX, IDC_UBOX_DIAL_NUMBER, m_S_Number); DDX_Control(pDX, IDC_UBOX_DIAL_TIP, m_S_Tip); DDX_Control(pDX, IDC_LIST, m_wndList); DDX_Control(pDX, IDC_UBOX_DIAL_NUMBER, m_E_Number); } BEGIN_MESSAGE_MAP(DLG_UBox_Dial, CDialogEx) ON_BN_CLICKED(IDC_UBOX_DIAL_1, &DLG_UBox_Dial::OnBnClickedUboxDial1) ON_BN_CLICKED(IDC_UBOX_DIAL_2, &DLG_UBox_Dial::OnBnClickedUboxDial2) ON_BN_CLICKED(IDC_UBOX_DIAL_3, &DLG_UBox_Dial::OnBnClickedUboxDial3) ON_BN_CLICKED(IDC_UBOX_DIAL_4, &DLG_UBox_Dial::OnBnClickedUboxDial4) ON_BN_CLICKED(IDC_UBOX_DIAL_5, &DLG_UBox_Dial::OnBnClickedUboxDial5) ON_BN_CLICKED(IDC_UBOX_DIAL_6, &DLG_UBox_Dial::OnBnClickedUboxDial6) ON_BN_CLICKED(IDC_UBOX_DIAL_7, &DLG_UBox_Dial::OnBnClickedUboxDial7) ON_BN_CLICKED(IDC_UBOX_DIAL_8, &DLG_UBox_Dial::OnBnClickedUboxDial8) ON_BN_CLICKED(IDC_UBOX_DIAL_9, &DLG_UBox_Dial::OnBnClickedUboxDial9) ON_BN_CLICKED(IDC_UBOX_DIAL_X, &DLG_UBox_Dial::OnBnClickedUboxDialX) ON_BN_CLICKED(IDC_UBOX_DIAL_0, &DLG_UBox_Dial::OnBnClickedUboxDial0) ON_BN_CLICKED(IDC_UBOX_DIAL_J, &DLG_UBox_Dial::OnBnClickedUboxDialJ) ON_BN_CLICKED(IDC_UBOX_DIAL_BACK, &DLG_UBox_Dial::OnBnClickedUboxDialBack) ON_BN_CLICKED(IDC_UBOX_DIAL_SETUP, &DLG_UBox_Dial::OnBnClickedUboxDialSetup) ON_BN_CLICKED(IDC_UBOX_DIAL_DIAL, &DLG_UBox_Dial::OnBnClickedUboxDialDial) ON_WM_TIMER() ON_MESSAGE( UBOX_EVENT , &DLG_UBox_Dial::UBox_Event ) ON_BN_CLICKED(IDC_UBOX_DIAL_LOG, &DLG_UBox_Dial::OnBnClickedUboxDialLog) ON_NOTIFY(NM_RDBLCLK, IDC_LIST, &DLG_UBox_Dial::OnNMRDblclkList) ON_NOTIFY(NM_DBLCLK, IDC_LIST, &DLG_UBox_Dial::OnNMDblclkList) END_MESSAGE_MAP() // DLG_UBox_Dial 消息处理程序 BOOL DLG_UBox_Dial::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 //初始化List m_Image.Create(16,16,ILC_COLOR32|ILC_MASK,5,5); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CALLIN) ); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CALLIN2) ); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CALLOUT) ); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_CALLOUT2) ); m_wndList.SubClassWindow2(); m_wndList.SetHeadings(_T("电话号码,130; 时间,80;")); m_wndList.SetGridLines(true); m_wndList.SetImageList(&m_Image,LVSIL_SMALL); this->OnBnClickedUboxDialLog(); m_E_Number.textColor(RGB(255,0,0)); m_E_Number.setFont(-24); m_E_Number.LimitText(20); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void DLG_UBox_Dial::AddNum(CString str) { if ( m_bCalling ) return ; m_strNumber = m_strNumber+str; if ( m_strNumber.GetLength()>20 ) { m_strNumber = m_strNumber.Left(20); } m_E_Number.SetWindowText(m_strNumber); } void DLG_UBox_Dial::OnBnClickedUboxDial1() { AddNum(_T("1")); } void DLG_UBox_Dial::OnBnClickedUboxDial2() { AddNum(_T("2")); } void DLG_UBox_Dial::OnBnClickedUboxDial3() { AddNum(_T("3")); } void DLG_UBox_Dial::OnBnClickedUboxDial4() { AddNum(_T("4")); } void DLG_UBox_Dial::OnBnClickedUboxDial5() { AddNum(_T("5")); } void DLG_UBox_Dial::OnBnClickedUboxDial6() { AddNum(_T("6")); } void DLG_UBox_Dial::OnBnClickedUboxDial7() { AddNum(_T("7")); } void DLG_UBox_Dial::OnBnClickedUboxDial8() { AddNum(_T("8")); } void DLG_UBox_Dial::OnBnClickedUboxDial9() { AddNum(_T("9")); } void DLG_UBox_Dial::OnBnClickedUboxDialX() { AddNum(_T("*")); } void DLG_UBox_Dial::OnBnClickedUboxDial0() { AddNum(_T("0")); } void DLG_UBox_Dial::OnBnClickedUboxDialJ() { AddNum(_T("#")); } void DLG_UBox_Dial::OnBnClickedUboxDialBack() { if ( m_bCalling ) return ; long lLen = m_strNumber.GetLength(); if ( lLen>0 ) { m_strNumber = m_strNumber.Left(lLen-1); m_E_Number.SetWindowText(m_strNumber); } } void DLG_UBox_Dial::OnBnClickedUboxDialSetup() { DLG_UBox_Setup dlg(this); if ( m_pMainFrame ) dlg.SetParam(m_pMainFrame->m_Setup); if ( dlg.DoModal() == IDOK ) { if ( m_pMainFrame ) { m_pMainFrame->m_Setup = dlg.GetParam(); m_pMainFrame->SaveSetup(); } } } void DLG_UBox_Dial::SetMainFrame(CMainFrame * pMainFrame) { m_pMainFrame = pMainFrame; } void DLG_UBox_Dial::OnBnClickedUboxDialDial() { #ifdef SUPPER_UBOX if ( m_pMainFrame ) { if ( m_bCalling ) { ShowTip(_T("通话结束后才能呼叫下一通电话!")); return ; } if ( m_strNumber.GetLength()<=0 ) { ShowTip(_T("请先输入电话号码再拨号!")); return ; } if ( m_pMainFrame->m_ubox_bPhoneUp ) { CString strNum = m_strNumber; long lNumLen = strNum.GetLength(); //去除区号 CString strLocalAreaCode = m_pMainFrame->m_Setup.UBox_strAreaCode; long lAreaCodeLen = strLocalAreaCode.GetLength(); if ( lAreaCodeLen>0 && lNumLen>lAreaCodeLen ) { if ( strNum.Left(lAreaCodeLen) == strLocalAreaCode ) { strNum = strNum.Right(lNumLen-lAreaCodeLen); } } //添加外呼前缀 CStringArray AddNum; SplitString(m_pMainFrame->m_Setup.UBox_strPhoneOutAddNumber,_T(",") , AddNum ); for( int i=0 ; i0 ) { strNum = strAddNum+strNum; break; /* long lNumLen = m_strNumber.GetLength(); if ( lNumLen>lAddNumLen ) { if ( strNum.Left(lAddNumLen) != strAddNum ) { strNum = strAddNum+strNum; } } */ } } //ClearNumber(); ClearCallOut(); #ifdef _UNICODE int abc = m_pMainFrame->m_ubox_send_dtmf(m_pMainFrame->m_ubox_endHandle,CW2A(strNum)); #else int abc = m_pMainFrame->m_ubox_send_dtmf(m_pMainFrame->m_ubox_endHandle,strNum); #endif } else { ShowTip(_T("请先拿起话筒再拨号!")); } } #endif } void DLG_UBox_Dial::ShowTip(CString strTip) { m_S_Tip.SetWindowText(strTip); SetTimer( 1 , 2000 , NULL ); } void DLG_UBox_Dial::OnTimer(UINT_PTR nIDEvent) { CDialogEx::OnTimer(nIDEvent); if ( nIDEvent==1 ) { KillTimer(nIDEvent); m_S_Tip.SetWindowText(_T("")); } if ( nIDEvent ==7 ) { KillTimer(nIDEvent); ClearCallOut(); CString strNumber = m_strNumber; ExMobileGZM(strNumber); long lNumLen = strNumber.GetLength(); BOOL bExAddNum=true; //判断是否为手机号码 if ( lNumLen>11 ) { CString str = strNumber.Left(2); if (str == CString(_T("12")) || str==CString(_T("13")) || str==CString(_T("14")) || str==CString(_T("15")) || str==CString(_T("16")) || str==CString(_T("17")) || str==CString(_T("18")) || str==CString(_T("19")) ) { bExAddNum = false; //是手机号码,不用再去除前缀了 } } if ( bExAddNum ) //需要去前缀 { //添加外呼前缀 CStringArray AddNum; SplitString(m_pMainFrame->m_Setup.UBox_strPhoneOutAddNumber,_T(",") , AddNum ); for( int i=0 ; ilAddLen ) { if ( strNumber.Left(lAddLen) == strAddNum ) { strNumber = strNumber.Right(lNumLen-lAddLen); break; } } } } ExMobileGZM(strNumber); m_pMainFrame->uboxPop_New(strNumber,1,1); //呼出弹屏,1秒后即计算接通 } } void DLG_UBox_Dial::ClearNumber() { m_bCalling =false; KillTimer(7); if ( m_strNumber.GetLength()>0 ) { m_strNumber = _T(""); m_E_Number.SetWindowText(m_strNumber); } } void DLG_UBox_Dial::ClearCallOut() { KillTimer(7); m_bCalling = true; } LONG_PTR DLG_UBox_Dial::UBox_Event( WPARAM wParam , LPARAM lParam ) { long lCmd = (long)wParam; CString str; if ( lCmd == UBOX_EVENT_CHAR ) //拨号 { if ( m_bCalling ) return 0; TCHAR number = (TCHAR)lParam; CString str(number); AddNum(str); //用于自动到时间计算为拨通号码 long lDelay = m_pMainFrame->m_Setup.UBox_lPhoneOutDelay; if ( lDelay <7 || lDelay>20 ) lDelay = 7; SetTimer( 7 , lDelay*1000 , NULL ); //自动接通 return true; } return 0; } void DLG_UBox_Dial::AddCallLog(CString strNumber,long lCallWay,long lCallStatus) { ANS_UBox_CallLog log={0}; log.lCallWay = lCallWay; log.lCallStatus = lCallStatus; m_wndList.InsertItem(0,strNumber,CFUBoxLog::GetCallLogIconIndex(&log)); CString str; SYSTEMTIME t;GetLocalTime(&t); str.Format(_T("%02d:%02d") , t.wHour,t.wMinute); m_wndList.SetItemText(0,1,str); } void DLG_UBox_Dial::PostNcDestroy() { // TODO: 在此添加专用代码和/或调用基类 CDialogEx::PostNcDestroy(); } void DLG_UBox_Dial::OnBnClickedUboxDialLog() { CRect rectwnd; this->GetWindowRect( &rectwnd ); CRect rectS1; GetDlgItem(IDC_UBOX_DIAL_LOG)->GetWindowRect( &rectS1 ); CRect rectS2; m_wndList.GetWindowRect( &rectS2 ); if ( m_bShowLog ) { rectwnd.right = rectS2.right+=15; this->MoveWindow( rectwnd ); GetDlgItem(IDC_UBOX_DIAL_LOG)->SetWindowText( _T("记录 <<") ); } else { rectwnd.right = rectS1.right+=15; this->MoveWindow( rectwnd ); GetDlgItem(IDC_UBOX_DIAL_LOG)->SetWindowText( _T("记录 >>") ); } m_bShowLog = !m_bShowLog; } void DLG_UBox_Dial::SetDialNumber(CString strNumber) { this->ShowWindow(SW_SHOW); this->SetForegroundWindow(); if ( m_bCalling ) ShowTip(_T("通话结束后才能呼叫下一通电话!")); m_strNumber =strNumber; m_E_Number.SetWindowText(strNumber); } long DLG_UBox_Dial::GetCurrentSelected() { POSITION pos = m_wndList.GetFirstSelectedItemPosition(); if ( pos ) { return m_wndList.GetNextSelectedItem(pos); } return -1; } void DLG_UBox_Dial::OnNMRDblclkList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); *pResult = 0; long lItem = GetCurrentSelected(); if ( lItem<0 ) return ; CString strNumber = m_wndList.GetItemText(lItem,0); SetDialNumber(strNumber); } void DLG_UBox_Dial::OnNMDblclkList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 *pResult = 0; long lItem = GetCurrentSelected(); if ( lItem<0 ) return ; CString strNumber = m_wndList.GetItemText(lItem,0); SetDialNumber(strNumber); } long DLG_UBox_Dial::SplitString(CString strSrc,CString strSplit,CStringArray & strRet ) { long lCount=0; try { strRet.RemoveAll(); strSrc = strSrc+strSplit; //后面加多一个分隔符 long lLen = strSrc.GetLength(); long lBegin=0; while(lBegin=0 ) { CString str = strSrc.Mid(lBegin,lFind-lBegin); if ( str.GetLength()>0 ) { strRet.Add(str); lCount ++; } lBegin = lFind+strSplit.GetLength(); } } } catch(...) { lCount=0; } return lCount; }