📄 smsdemodlg.cpp
字号:
// SMSDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SMSDemo.h"
#include "SMSDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSMSDemoDlg dialog
CSMSDemoDlg::CSMSDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSMSDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSMSDemoDlg)
m_AutoReceive = FALSE;
m_CenterNo = _T("");
m_Chinese = FALSE;
m_MobileNo = _T("");
m_Msg = _T("");
m_Rec = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSMSDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMSDemoDlg)
DDX_Control(pDX, IDC_CommPort, m_CommPort);
DDX_Control(pDX, IDC_Rate, m_Rate);
DDX_Control(pDX, IDC_MobileType, m_MobileType);
DDX_Check(pDX, IDC_AutoReceive, m_AutoReceive);
DDX_Text(pDX, IDC_CenterNo, m_CenterNo);
DDX_Check(pDX, IDC_Chinese, m_Chinese);
DDX_Text(pDX, IDC_MobileNo, m_MobileNo);
DDX_Text(pDX, IDC_Msg, m_Msg);
DDX_Text(pDX, IDC_Rec, m_Rec);
DDX_Control(pDX, IDC_SMS, m_SMS);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSMSDemoDlg, CDialog)
//{{AFX_MSG_MAP(CSMSDemoDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Connect, OnConnect)
ON_BN_CLICKED(IDC_disConnect, OndisConnect)
ON_BN_CLICKED(IDC_Send, OnSend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMSDemoDlg message handlers
BOOL CSMSDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//初始化
m_MobileType.AddString("标准手机");
m_MobileType.AddString("Wavecom模块");
m_MobileType.AddString("Nokia手机");
m_MobileType.AddString("西门子手机");
m_MobileType.SetCurSel(1);
m_Rate.AddString("9600,n,8,1");
m_Rate.AddString("19200,n,8,1");
m_Rate.AddString("38400,n,8,1");
m_Rate.AddString("57600,n,8,1");
m_Rate.AddString("115200,n,8,1");
m_Rate.SetCurSel(0);
m_CommPort.AddString("1");
m_CommPort.AddString("2");
m_CommPort.AddString("3");
m_CommPort.AddString("4");
m_CommPort.AddString("5");
m_CommPort.SetCurSel(0);
m_CenterNo="8613800100500";
m_AutoReceive = TRUE ;
m_Chinese = TRUE ;
UpdateData(FALSE);
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CSMSDemoDlg::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 CSMSDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSMSDemoDlg::OnConnect()
{
// TODO: Add your control notification handler code here
CString strMobileType;
CString strCommPort;
CString strRate;
UpdateData(TRUE);
if (m_AutoReceive == TRUE) //判断是否自动接收
{
m_SMS.SetAutoReceive(TRUE);
}
else
{
m_SMS.SetAutoReceive(FALSE);
}
m_MobileType.GetLBText(m_MobileType.GetCurSel(),strMobileType) ;
if (strMobileType == "标准手机")
{
m_SMS.SetMobileType(0);
}
if (strMobileType == "Wavecom模块")
{
m_SMS.SetMobileType(1);
}
if (strMobileType == "Nokia手机")
{
m_SMS.SetMobileType(2);
}
if (strMobileType == "西门子手机")
{
m_SMS.SetMobileType(3);
}
m_CommPort.GetLBText(m_CommPort.GetCurSel(),strCommPort) ;
m_SMS.SetCommPort(atoi(strCommPort));
m_SMS.SetCenterNo(m_CenterNo) ;
m_Rate.GetLBText(m_Rate.GetCurSel(),strRate) ;
m_SMS.SetSettings(strRate);
if (m_SMS.CommOpen() == 0)
{
MessageBox("连接成功!");
}
else
{
MessageBox("连接失败!");
}
}
void CSMSDemoDlg::OndisConnect()
{
// TODO: Add your control notification handler code here
m_SMS.CommClose();
MessageBox("断开成功!");
}
void CSMSDemoDlg::OnSend()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if (m_Chinese == TRUE)
{
if (m_SMS.SendMsg(m_MobileNo,m_Msg,TRUE,FALSE) == 0)
{
MessageBox("发送成功!");
}
else
{
MessageBox("发送失败!");
}
}
else
{
if (m_SMS.SendMsg(m_MobileNo,m_Msg,FALSE,FALSE) == 0)
{
MessageBox("发送成功!");
}
else
{
MessageBox("发送失败!");
}
}
}
BEGIN_EVENTSINK_MAP(CSMSDemoDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CSMSDemoDlg)
ON_EVENT(CSMSDemoDlg, IDC_SMS, 1 /* MsgReceived */, OnMsgReceivedSms, VTS_BSTR VTS_BSTR VTS_DATE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CSMSDemoDlg::OnMsgReceivedSms(LPCTSTR MsgSender, LPCTSTR Msg, DATE ArrivedTime)
{
// TODO: Add your control notification handler code here
m_Rec = Msg;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -