📄 smssend.cpp
字号:
// SMSSend.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "SMSSend.h"
#include "SMSSendDlg.h"
#include "SettingsDlg.h"
#include "Comm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString m_strPort;
CString m_strRate;
CString m_strSmsc;
char system_file[200];
char message_file[200];
char receive_file[200];
BOOL m_hand=0;
/////////////////////////////////////////////////////////////////////////////
// CSMSSendApp
BEGIN_MESSAGE_MAP(CSMSSendApp, CWinApp)
//{{AFX_MSG_MAP(CSMSSendApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMSSendApp construction
CSMSSendApp::CSMSSendApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSMSSendApp object
CSMSSendApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CSMSSendApp initialization
BOOL CSMSSendApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
GetModuleFileName(NULL,system_file,200);
int l=strlen(system_file);
for(int i=l;i>0;i--)
{
if(system_file[i-1]=='\\')
{
system_file[i-1]=0;
break;
}
}
strcpy(message_file,system_file);
strcat(message_file,"\\message.txt");
strcpy(receive_file,system_file);
strcat(receive_file,"\\receive.txt");
strcat(system_file,"\\system.dat");
CFile fp;
char str[10];
if(fp.Open(system_file,fp.modeRead|fp.typeBinary))
{
int i;
for(i=0;i<10;i++)
str[i]=0;
if(fp.Read(str,4)==4)
{
str[4]=0;
m_strPort=str;
fp.Read(str,6);
for(i=0;i<10;i++)
if(str[i]<'0'||str[i]>'9') str[i]=0;
m_strRate=str;
}
fp.Close();
}
else
{
if(fp.Open(system_file,fp.modeWrite|fp.modeCreate|fp.typeBinary))
{
m_strPort="COM1";
m_strRate="9600";
fp.Write(m_strPort,4);
fp.Write(m_strRate,4);
fp.Close();
}
}
m_strSmsc="13800240500";
CheckSettings();
// return FALSE;
CSMSSendDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
BOOL CSMSSendApp::CheckSettings()
{
int nRate;
sscanf(m_strRate, "%d", &nRate);
while (!::OpenComm(m_strPort, nRate))
{
CString strError;
strError.Format("无法打开端口%s! 现在设置吗?", m_strPort);
if (AfxMessageBox(strError, MB_YESNO) == IDNO) return FALSE;
CSettingsDlg dlg;
dlg.m_strPort = m_strPort;
dlg.m_strRate = m_strRate;
if (dlg.DoModal() == IDOK)
{
m_strPort = dlg.m_strPort;
m_strRate = dlg.m_strRate;
}
else
{
return FALSE;
}
}
if (!gsmInit())
{
AfxMessageBox("该端口上没有MODEM!或波特率不正确!");
return FALSE;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -