📄 smsrecvdlg.cpp
字号:
// SmsRecvDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SmsRecv.h"
#include "SmsRecvDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CSmsRecvDlg dialog
CSmsRecvDlg::CSmsRecvDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSmsRecvDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSmsRecvDlg)
m_nPort = 0;
m_strSpid = _T("");
m_strSpcode = _T("");
m_strPwd = _T("");
m_nSec = 0;
m_strMsg = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pCmpp = NULL;
}
void CSmsRecvDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSmsRecvDlg)
DDX_Control(pDX, IDC_SEC, m_secCtrl);
DDX_Control(pDX, IDC_PWD, m_pwdCtrl);
DDX_Control(pDX, IDC_PORT, m_portCtrl);
DDX_Control(pDX, IDC_SPCODE, m_spcodeCtrl);
DDX_Control(pDX, IDC_SPID, m_spidCtrl);
DDX_Control(pDX, IDC_IPADDRESS, m_IPCtrl);
DDX_Text(pDX, IDC_PORT, m_nPort);
DDX_Text(pDX, IDC_SPID, m_strSpid);
DDX_Text(pDX, IDC_SPCODE, m_strSpcode);
DDX_Text(pDX, IDC_PWD, m_strPwd);
DDX_Text(pDX, IDC_SEC, m_nSec);
DDX_Text(pDX, IDC_MSG, m_strMsg);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSmsRecvDlg, CDialog)
//{{AFX_MSG_MAP(CSmsRecvDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmsRecvDlg message handlers
BOOL CSmsRecvDlg::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_IPCtrl.SetAddress(192, 168, 0, 22);
m_portCtrl.SetLimitText(5);
m_portCtrl.SetWindowText("7890");
m_spidCtrl.SetWindowText("910000");
m_spcodeCtrl.SetWindowText("8888");
m_pwdCtrl.SetWindowText("111111");
m_secCtrl.SetWindowText("30");
CButton* btn = (CButton *)this->GetDlgItem(IDC_DISCONNECT);
btn->EnableWindow(FALSE);
btn = (CButton *)this->GetDlgItem(IDC_SEND);
btn->EnableWindow(FALSE);
btn = (CButton *)this->GetDlgItem(IDC_CONNECT);
btn->EnableWindow(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSmsRecvDlg::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 CSmsRecvDlg::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 CSmsRecvDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSmsRecvDlg::OnExit()
{
// TODO: Add your control notification handler code here
if( m_pCmpp )
{
delete m_pCmpp;
}
::SendMessage(this->m_hWnd, WM_CLOSE, NULL, NULL);
}
void CSmsRecvDlg::OnConnect()
{
// TODO: Add your control notification handler code here
BYTE b1,b2,b3,b4;
if(m_IPCtrl.IsBlank())
{
::AfxMessageBox("网关IP地址未填写!");
return;
}
m_IPCtrl.GetAddress(b1, b2, b3, b4);
sprintf(m_GatewayIP, "%d.%d.%d.%d\0", b1, b2, b3, b4);
UpdateData();
if(m_nPort<1 || m_nPort>65534)
{
::AfxMessageBox("端口值为1-65534之间的数字!");
return;
}
m_pCmpp = new CcmppSocket();
m_pCmpp->init(m_strSpid.GetBuffer(10), m_strPwd.GetBuffer(10), m_GatewayIP, m_nPort);
m_strSpid.ReleaseBuffer();
m_strPwd.ReleaseBuffer();
::AfxMessageBox("与网关连接成功!");
CButton* btn = (CButton *)this->GetDlgItem(IDC_CONNECT);
btn->EnableWindow(FALSE);
btn = (CButton *)this->GetDlgItem(IDC_DISCONNECT);
btn->EnableWindow(TRUE);
btn = (CButton *)this->GetDlgItem(IDC_SEND);
btn->EnableWindow(TRUE);
}
void CSmsRecvDlg::OnDisconnect()
{
// TODO: Add your control notification handler code here
CButton* btn = (CButton *)this->GetDlgItem(IDC_CONNECT);
btn->EnableWindow(TRUE);
btn = (CButton *)this->GetDlgItem(IDC_DISCONNECT);
btn->EnableWindow(FALSE);
btn = (CButton *)this->GetDlgItem(IDC_SEND);
btn->EnableWindow(FALSE);
if( m_pCmpp )
{
delete m_pCmpp;
m_pCmpp = NULL;
}
::AfxMessageBox("断开连接成功!");
}
void CSmsRecvDlg::OnSend()
{
// TODO: Add your control notification handler code here
UpdateData();
if( m_strMsg.GetLength() == 0)
{
::AfxMessageBox("请填写需要发送的内容!");
return;
}
CMPP_SUBMIT msg;
memset( (void *)&msg, 0, sizeof( msg));
msg.desttotal = 1;
strcpy( (char *)msg.destnumbers, "13808425257");
msg.msglen = m_strMsg.GetLength();
strcpy( (char *)msg.msgcontent, m_strMsg.GetBuffer(m_strMsg.GetLength()));
m_strMsg.ReleaseBuffer();
strcpy( (char *)msg.reserve, "abcdefgh");
strcpy( (char *)msg.msgsrc, m_strSpid.GetBuffer(10));
m_strSpid.ReleaseBuffer();
msg.pkgnumber=1;
msg.pkgtotal=1;
msg.delivery=1;
m_pCmpp->Submit(msg);
::AfxMessageBox("发送消息成功!");
}
void CSmsRecvDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if( m_pCmpp )
{
delete m_pCmpp;
m_pCmpp = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -