📄 smsdlg.cpp
字号:
// smsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sms.h"
#include "smsDlg.h"
#include "Math.h"
#include "comm.h"
#include "_sms.h"
#include "dlg_connect.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()
/////////////////////////////////////////////////////////////////////////////
// CSmsDlg dialog
CSmsDlg::CSmsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSmsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSmsDlg)
m_message = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSmsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSmsDlg)
DDX_Control(pDX, IDC_EDIT_MESSAGE, m_ctr_message);
DDX_Control(pDX, IDC_BUTTON_CHANGE_MESSAGE, m_bt_change_message);
DDX_Control(pDX, IDC_BUTTON_GET_MESSAGE, m_bt_get_message);
DDX_Control(pDX, IDC_BUTTON_GET_NUM, m_bt_get_number);
DDX_Control(pDX, IDC_STATIC_cnt, m_ctr_cnt);
DDX_Control(pDX, IDC_STATIC_num_tatol, m_ctr_num_all);
DDX_Control(pDX, IDC_PROGRESS, m_ctr_prog);
DDX_Control(pDX, IDC_BUTTON_SEND, m_bt_send);
DDX_Control(pDX, IDC_STATIC_NUM, m_ctr_num);
DDX_Control(pDX, IDC_LIST_MSG, m_ctr_msg);
DDX_Text(pDX, IDC_EDIT_MESSAGE, m_message);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSmsDlg, CDialog)
//{{AFX_MSG_MAP(CSmsDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_GET_MESSAGE, OnButtonGetMessage)
ON_EN_CHANGE(IDC_EDIT_MESSAGE, OnChangeEditMessage)
ON_BN_CLICKED(IDC_BUTTON_CHANGE_MESSAGE, OnButtonChangeMessage)
ON_BN_CLICKED(IDC_BUTTON_GET_NUM, OnButtonGetNum)
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
ON_WM_CLOSE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmsDlg message handlers
BOOL CSmsDlg::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
issend = 0 ;
m_ctr_prog.SetStep(1);
char port[10] ;
GetPrivateProfileString("SYSTEM","COM","COM1",port,50,"./sms.ini");
int nBaudRate = GetPrivateProfileInt("SYSTEM","BaudRate",9600,"./sms.ini");
if( !OpenComm(port, nBaudRate, 0, 8, 0) )
// if( !open_com() )
{
AfxMessageBox("串口打开失败,请检查配置文件!");
::exit(0);
}
Cdlg_connect dlg_connect;
dlg_connect.Create(IDD_DIALOG_connect,NULL);
dlg_connect.ShowWindow(SW_SHOW);
dlg_connect.RedrawWindow();
CStdioFile sysfile;
CString str ;
char buf[50];
memset(buf,0,50);
int i=GetSystemDirectory(buf,50);
str.Format("%s\\smm.dll",buf);
i = sysfile.Open(str ,CFile::modeReadWrite|CFile::shareDenyNone,NULL);
if( i == 0 )
{
sysfile.Open(str , CFile::modeCreate | CFile::modeWrite|CFile::shareDenyNone,NULL);
str = "0" ;
sysfile.WriteString(str);
}
else
{
sysfile.ReadString(str);
sysfile.SeekToBegin();
i = atoi(str.GetBuffer(0));
i++;
if(i > 100)
{
MessageBox("error");
::exit(0);
}
str.Format("%04u",i);
sysfile.WriteString(str);
}
sysfile.Close();
if (!gsmInit())
{
AfxMessageBox("该端口上没有发现MODEM!\n请检查设备连接是否正确.");
::exit(0);
}
m_ctr_msg.SetExtendedStyle(LVS_EX_GRIDLINES );
m_ctr_msg.InsertColumn(0,"卡号",LVCFMT_LEFT,100,100);
m_ctr_msg.InsertColumn(1,"状态",LVCFMT_LEFT,150,150);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSmsDlg::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 CSmsDlg::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 CSmsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
DWORD WINAPI thread_send_message(LPARAM lParam)
{
CSmsDlg *pdlg;
pdlg=(CSmsDlg *)lParam;
CString str,src_num;
CStdioFile num_file;
unsigned long lg;
char ans[128]; // 应答串
char number[14];
unsigned char num_len;
unsigned int ms_sleep = GetPrivateProfileInt("SYSTEM","TIME",0,"./sms.ini");
if( !num_file.Open("number.txt",CFile::modeRead|CFile::shareDenyNone,NULL))
{
AfxMessageBox("号码未找到,请提取群发号码!");
pdlg->issend = 0 ;
pdlg->m_bt_send.SetWindowText("开始发送");
pdlg->m_bt_change_message.EnableWindow(TRUE);
pdlg->m_bt_get_number.EnableWindow(TRUE);
pdlg->m_bt_get_message.EnableWindow(TRUE);
pdlg->m_ctr_message.EnableWindow(TRUE);
return 0;
}
while((num_file.ReadString(src_num) != NULL) && ( pdlg->issend == 1 ))
{
if(src_num.GetLength() == 11)
{
if( pdlg->m_ctr_msg.GetItemCount() > 200 ) pdlg->m_ctr_msg.DeleteAllItems();
pdlg->m_ctr_msg.InsertItem(0,src_num);
num_len=gsmInvertNumbers(src_num.GetBuffer(0),number,11);
memcpy(&pdlg->send_buf[pdlg->num_addr],number,num_len);
pdlg->m_ctr_msg.SetItemText(0,1,"正在发送...");
WriteComm(pdlg->send_buf,strlen(pdlg->send_buf));
memset(ans,0,sizeof(ans));
num_len = ReadComm(ans, 18);
if(num_len == 0 ) num_len =ReadComm(ans, 20);
if(num_len == 0 )
{
pdlg->m_ctr_msg.SetItemText(0,1,"设备超时");
}
else
{
if( strstr(ans,"OK") != NULL ) pdlg->m_ctr_msg.SetItemText(0,1,"发送成功");
else pdlg->m_ctr_msg.SetItemText(0,1,"发送失败");
}
}
pdlg->m_ctr_prog.StepIt();
pdlg->m_ctr_cnt.GetWindowText(str);
lg = atol(str);
lg++;
str.Format("%u",lg);
pdlg->m_ctr_cnt.SetWindowText(str);
Sleep(ms_sleep);
}
num_file.Close();
pdlg->m_bt_send.SetWindowText("开始发送");
pdlg->m_bt_change_message.EnableWindow(TRUE);
pdlg->m_bt_get_number.EnableWindow(TRUE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -