📄 evcsmsdlg.cpp
字号:
// EvcSmsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "EvcSms.h"
#include "EvcSmsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEvcSmsDlg dialog
CEvcSmsDlg::CEvcSmsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEvcSmsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEvcSmsDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEvcSmsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEvcSmsDlg)
DDX_Control(pDX, IDC_PHONENOEDIT, m_phonenoedit);
DDX_Control(pDX, IDC_CONTENTEDIT, m_contentedit);
DDX_Control(pDX, IDC_MSGSTATIC, m_msgstatic);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEvcSmsDlg, CDialog)
//{{AFX_MSG_MAP(CEvcSmsDlg)
ON_BN_CLICKED(IDC_SENDBTN, OnSendbtn)
ON_BN_CLICKED(IDC_RECEIVEBTN, OnReceivebtn)
ON_BN_CLICKED(IDC_CALLBTN, OnCallbtn)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_HANGONBTN, OnHangonbtn)
ON_BN_CLICKED(IDC_HANGUPBTN, OnHangupbtn)
ON_BN_CLICKED(IDC_RESETBTN, OnResetbtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEvcSmsDlg message handlers
BOOL CEvcSmsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
BOOL ret = MyMobile.ConnectMobile(1, 115200, 8, NOPARITY, ONESTOPBIT);
if(!ret)
AfxMessageBox(_T("ConnectMobile Fail"));
m_phonenoedit.SetWindowText(_T("13386273322"));
m_contentedit.SetWindowText(_T("测试短信,test sms。"));
SetTimer(100, 1000, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CEvcSmsDlg::OnSendbtn()
{
// TODO: Add your control notification handler code here
CString strSMS;
m_contentedit.GetWindowText(strSMS);
CString strPhoneNO;
m_phonenoedit.GetWindowText(strPhoneNO);
int smslen = WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strSMS.GetBuffer(0),
strSMS.GetLength(),
NULL,
0,
NULL,
NULL);
char* sms = new char[smslen];
WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strSMS.GetBuffer(0),
strSMS.GetLength(),
sms,
smslen,
NULL,
NULL);
int phonenolen = WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strPhoneNO.GetBuffer(0),
strPhoneNO.GetLength(),
NULL,
0,
NULL,
NULL);
char* phoneno = new char[phonenolen];
WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strPhoneNO.GetBuffer(0),
strPhoneNO.GetLength(),
phoneno,
phonenolen,
NULL,
NULL);
BOOL ret = MyMobile.SendSMS("lionsoft34224281", phoneno, sms);
delete []phoneno;
delete []sms;
if(ret)
AfxMessageBox(_T("SendSms Success"));
else
AfxMessageBox(_T("SendSms Fail"));
}
void CEvcSmsDlg::OnReceivebtn()
{
// TODO: Add your control notification handler code here
char strPhoneNumber[256];
char strText[256];
BOOL ret = MyMobile.ReceiveSMS("lionsoft34224281", strPhoneNumber, strText);
if(ret)
{
AfxMessageBox(_T("ReceiveSMS Success"));
CString msg = strText;
AfxMessageBox(msg);
}
else
AfxMessageBox(_T("ReceiveSMS Fail"));
}
BOOL CEvcSmsDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
MyMobile.DisConnectMobile();
return CDialog::DestroyWindow();
}
void CEvcSmsDlg::OnCallbtn()
{
// TODO: Add your control notification handler code here
CString strPhoneNO;
m_phonenoedit.GetWindowText(strPhoneNO);
int phonenolen = WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strPhoneNO.GetBuffer(0),
strPhoneNO.GetLength(),
NULL,
0,
NULL,
NULL);
char* phoneno = new char[phonenolen];
WideCharToMultiByte(CP_ACP,
WC_COMPOSITECHECK,
strPhoneNO.GetBuffer(0),
strPhoneNO.GetLength(),
phoneno,
phonenolen,
NULL,
NULL);
MyMobile.Dial(phoneno);
delete []phoneno;
}
void CEvcSmsDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 100)
{
MyMobile.ReadResponse();
if(MyMobile.CheckRing())
m_msgstatic.SetWindowText(_T("Ring"));
else if(MyMobile.CheckNewSMS())
m_msgstatic.SetWindowText(_T("NewSMS"));
else
m_msgstatic.SetWindowText(_T(""));
}
CDialog::OnTimer(nIDEvent);
}
void CEvcSmsDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
KillTimer(100);
}
void CEvcSmsDlg::OnHangonbtn()
{
// TODO: Add your control notification handler code here
MyMobile.Hangon();
}
void CEvcSmsDlg::OnHangupbtn()
{
// TODO: Add your control notification handler code here
MyMobile.Hangup();
}
void CEvcSmsDlg::OnResetbtn()
{
// TODO: Add your control notification handler code here
MyMobile.Reset();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -