📄 smssenddlg.cpp
字号:
// smssendDlg.cpp : implementation file
//
#include "stdafx.h"
#include "smssend.h"
#include "smssendDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmssendDlg dialog
CSmssendDlg::CSmssendDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSmssendDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSmssendDlg)
m_Edit1 = _T("");
m_Edit2 = _T("");
m_check1 = FALSE;
m_check2 = FALSE;
m_c4 = _T("");
m_Edit5 = _T("");
m_Edit4 = _T("");
m_Edit3 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nTimeCount=0;
}
void CSmssendDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSmssendDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_Process);
DDX_Control(pDX, IDC_STATIC1, m_Static1Ctrl);
DDX_Control(pDX, IDC_COMBO3, m_c3);
DDX_Control(pDX, IDC_COMBO2, m_c2);
DDX_Control(pDX, IDC_COMBO1, m_c1);
DDX_Control(pDX, IDC_SMS, m_sms1);
DDX_Text(pDX, IDC_EDIT1, m_Edit1);
DDX_Text(pDX, IDC_EDIT2, m_Edit2);
DDX_Check(pDX, IDC_CHECK1, m_check1);
DDX_Check(pDX, IDC_CHECK2, m_check2);
DDX_CBString(pDX, IDC_COMBO4, m_c4);
DDX_Text(pDX, IDC_EDIT5, m_Edit5);
DDX_Text(pDX, IDC_EDIT4, m_Edit4);
DDX_Text(pDX, IDC_EDIT3, m_Edit3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSmssendDlg, CDialog)
//{{AFX_MSG_MAP(CSmssendDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmssendDlg message handlers
BOOL CSmssendDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
//初始化设置
m_sms1.ShowWindow(SW_HIDE);
m_sms1.SetSendTimeout(8);
m_c1.SetCurSel(0);
m_c2.SetCurSel(1);
m_c3.SetCurSel(0);
m_sms1.SetSendmode("1");
m_check2=TRUE;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSmssendDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSmssendDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSmssendDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSmssendDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CSmssendDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CSmssendDlg::OnButton7()
{
//AT命令
UpdateData();
m_Edit5=m_sms1.ATcommand((LPCTSTR)m_c4);
UpdateData(FALSE);
}
void CSmssendDlg::OnButton1()
{
UpdateData();
//设置串口号
CString ComText;
if (m_c1.GetCurSel()!=-1)
{m_c1.GetLBText(m_c1.GetCurSel(),ComText);
ComText=ComText.Mid(3);
m_sms1.SetCommport(::atoi(ComText));
}
//设置波特率
if (m_c2.GetCurSel()!=-1)
{m_c2.GetLBText(m_c2.GetCurSel(),ComText);
m_sms1.SetSetting((LPCTSTR)ComText);
}
//打开与手机的通讯
if (m_sms1.Commopen()==(short)1)
MessageBox("连接成功!");
else
MessageBox("连接失败!");
}
void CSmssendDlg::OnButton3()
{
//检测连接
VARIANT str=m_sms1.CheckConnection();
switch(str.intVal)
{case 1:MessageBox("已经连接!");break;
case 2:MessageBox("发送机忙!");break;
default:MessageBox("连接错误!");
}
}
void CSmssendDlg::OnButton2()
{
//关闭与手机的连接
m_sms1.Commclose();
MessageBox("断开成功!");
}
void CSmssendDlg::OnButton4()
{
//发送短信
UpdateData();
//设置进度条
m_Process.SetRange(0,m_sms1.GetSendTimeout());
//设置定时器
SetTimer(111,1000,NULL);
//定时值归零
m_nTimeCount=0;
CString SmsType;
if (m_c3.GetCurSel()!=-1)
{//获取发送方式
m_c3.GetLBText(m_c3.GetCurSel(),SmsType);
m_Process.SetPos(0);
if (m_sms1.GetSendmode()=="1")
{//方式1发送
if (m_sms1.Sendmsg((LPCTSTR)m_Edit1,(LPCTSTR)m_Edit2,(LPCTSTR)SmsType)==(short)1)
{
m_Process.SetPos(0);
KillTimer(111);
MessageBox("发送成功!");
}
else
{
m_Process.SetPos(0);
KillTimer(111);
MessageBox("发送失败!");
}
}
else
{//方式2发送
if (m_sms1.Sendmsg((LPCTSTR)m_Edit1,(LPCTSTR)m_Edit2,(LPCTSTR)SmsType)==(short)1)
{
m_Process.SetPos(0);
KillTimer(111);
MessageBox("提交成功!");
}
else
{
m_Process.SetPos(0);
KillTimer(111);
MessageBox("提交失败!");
}
}
}
}
void CSmssendDlg::OnTimer(UINT nIDEvent)
{
if (nIDEvent==(UINT)111)
{//发送过程
m_nTimeCount++;
if (m_nTimeCount > m_sms1.GetSendTimeout())
m_nTimeCount=m_sms1.GetSendTimeout();
m_Process.SetPos(m_nTimeCount);
}
CDialog::OnTimer(nIDEvent);
}
void CSmssendDlg::OnCheck1()
{
//设置自动接收
UpdateData();
m_sms1.SetAutoreceive(m_check1);
}
void CSmssendDlg::OnCheck2()
{
//设置自动删除
UpdateData();
m_sms1.SetAutodelmsg(m_check2);
}
void CSmssendDlg::OnButton6()
{
//读短信
UpdateData();
if (!m_Edit4.IsEmpty())
{
//从控件的属性中取得刚才读出的短信内容
if (m_sms1.Readmsg(::atoi(m_Edit4))==(short)1)
MessageBox("读短信息成功!");
else
MessageBox("读短信息失败!");
}
}
void CSmssendDlg::OnChangeEdit2()
{
//更新剩余字符值
UpdateData();
CString Temp;
Temp.Format("%d",m_Edit2.GetLength());
m_Static1Ctrl.SetWindowText(Temp);
}
BEGIN_EVENTSINK_MAP(CSmssendDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSmssendDlg)
ON_EVENT(CSmssendDlg, IDC_SMS, 1 /* Msgreceived */, OnMsgreceivedSms, VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR)
ON_EVENT(CSmssendDlg, IDC_SMS, 2 /* Sendreport */, OnSendreportSms, VTS_BSTR VTS_BSTR VTS_BSTR)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CSmssendDlg::OnMsgreceivedSms(LPCTSTR arrivedate, LPCTSTR arrivetime, LPCTSTR smssender, LPCTSTR Msg)
{
//读取短信事件
UpdateData();
m_Edit3+=arrivedate;
m_Edit3+=arrivetime;
m_Edit3+=smssender;
m_Edit3+=Msg;
m_Edit3+="\r\n";
UpdateData(FALSE);
}
void CSmssendDlg::OnSendreportSms(LPCTSTR Outmbno, LPCTSTR Outmsg, LPCTSTR Report)
{
//使用方式2发送时的返回报告
KillTimer(111);
m_Process.SetPos(0);
CString DisplayString;
DisplayString=Outmbno;
DisplayString+=Outmsg;
DisplayString+=Report;
MessageBox(DisplayString);
}
void CSmssendDlg::OnDestroy()
{
CDialog::OnDestroy();
//退出关闭
m_sms1.Commclose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -