📄 sendsms.cpp
字号:
// SendSms.cpp : implementation file
//
#include "stdafx.h"
#include "GpsTest.h"
#include "SendSms.h"
#include "StatusSelect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSendSms dialog
CSendSms::CSendSms(CWnd* pParent /*=NULL*/)
: CDialog(CSendSms::IDD, pParent)
{
//{{AFX_DATA_INIT(CSendSms)
m_strSmsDisplay = _T("");
m_strStatus = _T("");
m_date = COleDateTime::GetCurrentTime();
m_time = COleDateTime::GetCurrentTime();
m_nCmdSN = 1;
m_nCourse = 0;
m_nCount = 0;
m_nInterval = 0;
m_nLatitude = 0.0;
m_nLongitude = 0.0;
m_dSpeed = 0.0;
//}}AFX_DATA_INIT
// m_edtStatus.SetBrowseStyle(BES_XT_CHOOSEDIR);
m_butCreateSms.SetBitmap(CSize(16,16), IDB_SMS);
m_butCreateSms.SetXButtonStyle(BS_XT_SEMIFLAT);
m_butSelect.SetXButtonStyle(BS_XT_SEMIFLAT);
m_butOk.SetBitmap(CSize(16,16), IDB_OK);
m_butOk.SetXButtonStyle(BS_XT_SEMIFLAT);
m_butCancle.SetBitmap(CSize(16,16), IDB_CANCLE);
m_butCancle.SetXButtonStyle(BS_XT_SEMIFLAT);
}
void CSendSms::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendSms)
DDX_Control(pDX, IDC_BUTTON_CREATESMS, m_butCreateSms);
DDX_Control(pDX, IDC_DATETIMEPICKER_TIME, m_ctlTime);
DDX_Control(pDX, IDC_DATETIMEPICKER_DATE, m_ctlDate);
DDX_Control(pDX, IDC_BUTTON_SELECT, m_butSelect);
DDX_Control(pDX, IDC_EDIT_STATUS, m_edtStatus);
DDX_Control(pDX, IDC_EDIT_SPEED, m_edtSpeed);
DDX_Control(pDX, IDC_EDIT_SMSDISPLY, m_edtSmsDisplay);
DDX_Control(pDX, IDC_EDIT_INTERVAL, m_edtInterval);
DDX_Control(pDX, IDC_EDIT_COURSE, m_edtCourse);
DDX_Control(pDX, IDC_EDIT_COUNT, m_edtCount);
DDX_Control(pDX, IDC_EDIT_CMDSN, m_edtCmdSN);
DDX_Control(pDX, IDC_EDIT_LONGITUDE, m_edtLongitidue);
DDX_Control(pDX, IDC_EDIT_LATITUDE, m_edtLatitude);
DDX_Control(pDX, IDOK, m_butOk);
DDX_Control(pDX, IDCANCEL, m_butCancle);
DDX_Text(pDX, IDC_EDIT_SMSDISPLY, m_strSmsDisplay);
DDX_Text(pDX, IDC_EDIT_STATUS, m_strStatus);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_DATE, m_date);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_TIME, m_time);
DDX_Text(pDX, IDC_EDIT_CMDSN, m_nCmdSN);
DDX_Text(pDX, IDC_EDIT_COURSE, m_nCourse);
DDV_MinMaxInt(pDX, m_nCourse, 0, 360);
DDX_Text(pDX, IDC_EDIT_COUNT, m_nCount);
DDV_MinMaxInt(pDX, m_nCount, 0, 65535);
DDX_Text(pDX, IDC_EDIT_INTERVAL, m_nInterval);
DDV_MinMaxInt(pDX, m_nInterval, 30, 65535);
DDX_Text(pDX, IDC_EDIT_LATITUDE, m_nLatitude);
DDX_Text(pDX, IDC_EDIT_LONGITUDE, m_nLongitude);
DDX_Text(pDX, IDC_EDIT_SPEED, m_dSpeed);
DDV_MinMaxDouble(pDX, m_dSpeed, 0., 999.99);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSendSms, CDialog)
//{{AFX_MSG_MAP(CSendSms)
ON_BN_CLICKED(IDC_BUTTON_SELECT, OnButtonSelect)
ON_BN_CLICKED(IDC_RADIO_DW, OnRadioDw)
ON_BN_CLICKED(IDC_BUTTON_CREATESMS, OnButtonCreatesms)
ON_BN_CLICKED(IDC_RADIO_BJ, OnRadioBj)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSendSms message handlers
BOOL CSendSms::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GetSmsConfig();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSendSms::OnButtonSelect()
{
// TODO: Add your control notification handler code here
CStatusSelect statusDlg;
int nRet;
statusDlg.m_strSmsStatus = m_strStatus;
nRet = statusDlg.DoModal();
if (nRet == IDOK)
{
m_strStatus = statusDlg.m_strSmsStatus;
// MessageBox("Select the Car Status!", "haha", MB_ICONWARNING);
}
else
{
return;
}
UpdateData(FALSE);
}
void CSendSms::OnOK()
{
// TODO: Add extra validation here
if (m_strSmsDisplay.IsEmpty())
{
MessageBox("短信内容不能为空!\r\n", "错误信息", MB_ICONWARNING);
return;
}
CDialog::OnOK();
}
int CSendSms::GetSmsConfig()
{
CString section;
CString strConfigFileName;
char cStore1[64];
char cStore2[16];
char cStore3[16];
char cStore4[16];
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "SMS";
memset(cStore1, 0, 64);
memset(cStore2, 0, 16);
memset(cStore3, 0, 16);
memset(cStore4, 0, 16);
GetPrivateProfileString(section, "SN", "1000", cStore1, 64, strConfigFileName);
GetPrivateProfileString(section, "DW_Interval", "30", cStore2, 16, strConfigFileName);
GetPrivateProfileString(section, "DW_CountLeft", "1", cStore3, 16, strConfigFileName);
GetPrivateProfileString(section, "Status", "010000000200", cStore4, 16, strConfigFileName);
m_nCmdSN = atoi(cStore1);
m_nInterval = atoi(cStore2);
m_nCount = atoi(cStore3);
m_strStatus = cStore4;
return 0;
}
int CSendSms::SetSmsConfig()
{
CString section;
CString strConfigFileName;
CString str1,str2,str3;
strConfigFileName = g_strPath;
strConfigFileName += "\\config.ini";
section = "SMS";
str1.Format("%d", m_nCmdSN);
str2.Format("%d", m_nInterval);
str3.Format("%d", m_nCount);
WritePrivateProfileString(section, "SN", str1, strConfigFileName);
WritePrivateProfileString(section, "DW_Interval", str2, strConfigFileName);
WritePrivateProfileString(section, "DW_CountLeft", str3, strConfigFileName);
WritePrivateProfileString(section, "Status", m_strStatus, strConfigFileName);
return 0;
}
void CSendSms::OnRadioDw()
{
// TODO: Add your control notification handler code here
SetSmsType(SMS_CMD_DW);
}
void CSendSms::OnRadioBj()
{
// TODO: Add your control notification handler code here
SetSmsType(SMS_CMD_BJ);
}
void CSendSms::OnButtonCreatesms()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString strCmdSms = "*";
CString strCmdSN, strpara;
UINT nSmsType = GetSmsType();
strCmdSN.Format(",%.8x", m_nCmdSN);
if (nSmsType == SMS_CMD_DW)
{
strCmdSms += strCmdSN;
strpara.Format(",DW,%.4x,%.4x", m_nCount, m_nInterval);
strCmdSms += strpara;
}
else if (nSmsType == SMS_CMD_BJ)
{
strCmdSms += ",00000000";
strpara.Format(",BJ");
strCmdSms += strpara;
}
else
{
return;
}
CString strCommSms = CreateCommSms();
m_strSmsDisplay = strCmdSms + strCommSms;
m_strSmsDisplay += m_strStatus;
SetSmsConfig();
UpdateData(FALSE);
}
CString CSendSms::CreateCommSms()
{
CString strCommSms = ",A";
CString strDateTime, strPosition;
strDateTime.Format(",%.2x%.2x%.2x,%.2x%.2x%.2x",
m_date.GetYear()-2000, m_date.GetMonth(),m_date.GetDay(),
m_time.GetHour(), m_time.GetMinute(), m_time.GetSecond());
long tempLatitude = (long)(m_nLatitude*600000);
long tempLongitude = (long)(m_nLongitude*600000);
int tempSpeed = (int)(m_dSpeed*100);
strPosition.Format(",%.8x,%.8x,%.4x,%.4x,", tempLatitude, tempLongitude, tempSpeed, m_nCourse);
strCommSms += strDateTime;
strCommSms += strPosition;
return strCommSms;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -