📄 smsformview.cpp
字号:
// SMSFormView.cpp : implementation file
//
#include "stdafx.h"
#include "sms.h"
#include "SMSFormView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CSMSApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSMSFormView
IMPLEMENT_DYNCREATE(CSMSFormView, CFormView)
CSMSFormView::CSMSFormView()
: CFormView(CSMSFormView::IDD)
{
//{{AFX_DATA_INIT(CSMSFormView)
m_MessageContent = _T("");
m_PhoneNumber = _T("");
//}}AFX_DATA_INIT
}
CSMSFormView::~CSMSFormView()
{
}
void CSMSFormView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMSFormView)
DDX_Control(pDX, IDC_PHONE_NUMBER, m_CtrPhoneNumber);
DDX_Text(pDX, IDC_MESSAGE_CONTENT, m_MessageContent);
DDV_MaxChars(pDX, m_MessageContent, 700);
DDX_CBString(pDX, IDC_PHONE_NUMBER, m_PhoneNumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSMSFormView, CFormView)
//{{AFX_MSG_MAP(CSMSFormView)
ON_BN_CLICKED(IDC_SEND, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMSFormView diagnostics
#ifdef _DEBUG
void CSMSFormView::AssertValid() const
{
CFormView::AssertValid();
}
void CSMSFormView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSMSFormView message handlers
void CSMSFormView::OnSend()
{
// TODO: Add your control notification handler code here
UpdateData();
////////////////////////////////////////////////////////////////////////
//发送
////////////////////////////////////////////////////////////////////////
// CSmsSerialPort * SmsSerialPort=&(((CMainFrame *)(AfxGetApp()->GetMainWnd()))->m_SmsSerialPort);
//
//////////////////////////////////////////////////////////////////////////
//验证是否接边接到猫
if(!theApp.m_SmsSerialPort.IsRunning())
{
AfxMessageBox("还未连接猫\n请连接猫");
return;
}
//////////////////////////////////////////////////////////////////////////
//对输入的手机号进行验证
if(m_PhoneNumber.IsEmpty())
{
AfxMessageBox("请输入手机号码");
return;
}
//判断手机号是否存在非数字字符的存在
//判断号码的最大长度为24个字节,必须为数字或+号
int i=0;
BOOL isRight=TRUE;
//判断是否以数字或+开头
for(i=0;i<m_PhoneNumber.GetLength();i++)
{
if(! (isdigit(m_PhoneNumber[i]) || m_PhoneNumber[0]=='+' && i==0 ))
{
isRight=FALSE;
}
}
TRACE("号码为%s %d",m_PhoneNumber,isRight);
//在号码格式正确的基础上再判断号码的最大长度是否超过24
if(!(isRight && m_PhoneNumber.GetLength()<=24))
{
AfxMessageBox("手机号码不能超过24位并且不能包含非数字字符");
return;
}
//////////////////////////////////////////////////////////////////////////
//对手机号加86
//要先对"+"进行处理,而不能先判断是否以"86"开头
if("+"==m_PhoneNumber.Left(1))
{
m_PhoneNumber=m_PhoneNumber.Mid(1);
}
//如果手机号不以86就给他补个86进去
if("86"!=m_PhoneNumber.Left(2))
{
m_PhoneNumber="86"+m_PhoneNumber;
}
//TRACE("%s\n",temp);
//////////////////////////////////////////////////////////////////////////
//将要发送的内容放入到发送队列
//////////////////////////////////////////////////////////////////////////
if(m_MessageContent.IsEmpty())
{
AfxMessageBox("短信内容不能为空");
return;
}
std::vector<CString> sendList;
while(1)
{
if(m_MessageContent.GetLength()<=140)
{
sendList.push_back(m_MessageContent);
break;
}
else
{
sendList.push_back(InterceptString(m_MessageContent));
}
}
if(sendList.size()>5)
{
AfxMessageBox("短信内容超过5条短信所发送长度");
return;
}
//StringCovertToPhoneNumber(m_PhoneNumber);
CSmsSerialPort * SmsSerialPort=&(theApp.m_SmsSerialPort);
CString serverCenterNumber=theApp.m_ServeCenterNumber;
int size=sendList.size();
int j=0;
//SM_PARAM Note=SmsSerialPort->NoteMessage("8613800591500",m_PhoneNumber,m_MessageContent,-1);
for(;j<size;j++)
{
SM_PARAM Note=SmsSerialPort->NoteMessage(serverCenterNumber,m_PhoneNumber,sendList[j],-1);
SmsSerialPort->PutToSendMessageList(Note);
//将要发送的内容放到发送队列中去
}
//SM_PARAM Note=SmsSerialPort->NoteMessage(serverCenterNumber,m_PhoneNumber,m_MessageContent,-1);
//SmsSerialPort->PutToSendMessageList(Note);
}
BOOL CSMSFormView::StringCovertToPhoneNumber(CString &phoneNumber)
{
if(phoneNumber[0] == '+')
{
phoneNumber.Delete(0);//删除'+'
}
if(phoneNumber.Left(2).Compare("86") != 0)//不以86开头的情况下要添加"86"
{
phoneNumber.Insert(0,"86");
}
if(phoneNumber.GetLength() !=13 )
return FALSE;
else
return TRUE;
}
BOOL CSMSFormView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_RETURN) return TRUE;
if (pMsg->wParam == VK_ESCAPE) return TRUE;
}
return CFormView::PreTranslateMessage(pMsg);
}
CString CSMSFormView::InterceptString(CString &sendStr)
{
CString strTemp=sendStr.Left(140);
CString returnString;
int i=0;
for(i=0;i<139;)
{
if (IsDBCSLeadByte(strTemp[i]))
i+=2;
else
i++;
}
if (i==140)
returnString=strTemp;
else
returnString=strTemp.Left(139);
sendStr.Delete(0,returnString.GetLength());
return returnString;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -