📄 sendsmdlg.cpp
字号:
// SendSMDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SendSM.h"
#include "SendSMDlg.h"
#include "ReceiveSMThread.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CSendSMApp theApp;
CWinThread * m_pReceiveSMThread = NULL;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSendSMDlg dialog
CSendSMDlg::CSendSMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSendSMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSendSMDlg)
m_Dst_Adr = _T("");
m_Msg = _T("");
m_Sur_Adr = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSendSMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSendSMDlg)
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Text(pDX, IDC_DST_ADR, m_Dst_Adr);
DDV_MaxChars(pDX, m_Dst_Adr, 11);
DDX_Text(pDX, IDC_MSG, m_Msg);
DDV_MaxChars(pDX, m_Msg, 140);
DDX_Text(pDX, IDC_SUR_ADR, m_Sur_Adr);
DDV_MaxChars(pDX, m_Sur_Adr, 11);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSendSMDlg, CDialog)
//{{AFX_MSG_MAP(CSendSMDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_RESTART, OnRestart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSendSMDlg message handlers
BOOL CSendSMDlg::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
m_List.InsertColumn(0,"时间",LVCFMT_LEFT,150);
m_List.InsertColumn(1,"对象信息",LVCFMT_LEFT,450);
if(!theApp.Login())
{
(CButton*)GetDlgItem(IDC_OK)->EnableWindow(false);
}
//CWinApp::SetDialogBkColor();
// TODO: Add extra initialization here
m_pReceiveSMThread = AfxBeginThread(RUNTIME_CLASS(CReceiveSMThread));
return TRUE; // return TRUE unless you set the focus to a control
}
void CSendSMDlg::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 CSendSMDlg::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 CSendSMDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSendSMDlg::OnOk()
{
UpdateData(true);
m_Sur_Adr.TrimLeft();
m_Sur_Adr.TrimRight();
m_Dst_Adr.TrimLeft();
m_Dst_Adr.TrimRight();
m_Msg.TrimLeft();
m_Msg.TrimRight();
if (m_Sur_Adr.IsEmpty())
{
AfxMessageBox("发信人信息不能为空!");
return;
}
if (m_Sur_Adr.GetLength() > 11)
{
AfxMessageBox("发信人信息长度不能超过13个数字、英文字母或6个汉字!");
return;
}
if (m_Dst_Adr.IsEmpty())
{
AfxMessageBox("对方手机号码不能为空!");
return;
}
if (m_Dst_Adr.GetLength() > 11)
{
AfxMessageBox("对方手机号码长度不能超过13个数字!");
return;
}
if (m_Msg.IsEmpty())
{
AfxMessageBox("短信内容不能为空!");
return;
}
if (m_Msg.GetLength() > 140)
{
AfxMessageBox("短信内容长度不能超过140个数字、英文字母或70个汉字!");
return;
}
(CButton*)GetDlgItem(IDC_OK)->EnableWindow(false);
SendSM();
(CButton*)GetDlgItem(IDC_OK)->EnableWindow(true);
UpdateData(false);
}
void CSendSMDlg::SendSM()
{
CString m_Msg1;
cmppe_submit cs;
dpl_status_t stat;
/*向手机用户提交消息的测试*/
memset(&cs,0,sizeof(cmppe_submit));
theApp.submit_value_set(&cs,m_Sur_Adr,m_Dst_Adr,m_Msg);
stat = cmpp_submit(&theApp.conn,&cs);
if(stat != DPL_SUCCESS)
{
m_Msg1.Format("发送给(%s)的短信(%s)发送失败!",m_Dst_Adr,m_Msg);
theApp.AddToList(m_Msg1);
}
}
void CSendSMDlg::OnClear()
{
m_List.DeleteAllItems();
}
void CSendSMDlg::OnDestroy()
{
CDialog::OnDestroy();
//释放各模块
theApp.m_bExitFlag = true;
Sleep(100);
while(m_pReceiveSMThread)
{
DWORD exitCode;
if ( m_pReceiveSMThread && GetExitCodeThread(m_pReceiveSMThread->m_hThread,&exitCode)
&& exitCode != STILL_ACTIVE)
{
delete m_pReceiveSMThread;
m_pReceiveSMThread = NULL;
}
Sleep(50);
}
theApp.m_bExitFlag = false;
}
void CSendSMDlg::OnRestart()
{
theApp.Logout();
Sleep(10000);
theApp.Login();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -