CorpSms/DLG_UBox_Dial.cpp

546 lines
11 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 ; i<AddNum.GetCount() ; i++ )
{
CString strAddNum = AddNum.GetAt(i);
long lAddNumLen = strAddNum.GetLength();
if ( lAddNumLen>0 )
{
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 ; i<AddNum.GetCount() ; i++ )
{
CString strAddNum = AddNum.GetAt(i);
long lAddLen = strAddNum.GetLength();
if ( lNumLen>lAddLen )
{
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<LPNMITEMACTIVATE>(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<LPNMITEMACTIVATE>(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<lLen)
{
long lFind = strSrc.Find(strSplit,lBegin);
if ( lFind>=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;
}