📄 smsviagatewaydlg.cpp
字号:
// SMSViaGatewayDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SMSViaGateway.h"
#include "SMSViaGatewayDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define EDIT_MAX_TEXT 1024*20 // CEdit 控件最大容纳的文本
void AddLogTextToEditCtrl ( CEdit *pEditLog, LPCTSTR lpszLogText )
{
ASSERT ( lpszLogText );
if ( !pEditLog || !::IsWindow ( pEditLog->m_hWnd ) )
return;
CString csLog;
pEditLog->GetWindowText ( csLog );
int nTextLen = csLog.GetLength ();
CString csTemp = lpszLogText;
if ( ::IsWindow ( pEditLog->m_hWnd ) )
{
if ( nTextLen < EDIT_MAX_TEXT )
{
pEditLog->SetSel ( nTextLen, -1, TRUE );
}
else
{
pEditLog->SetSel ( 0, -1, TRUE );
}
pEditLog->ReplaceSel( csTemp );
}
}
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMSViaGatewayDlg dialog
CSMSViaGatewayDlg::CSMSViaGatewayDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSMSViaGatewayDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSMSViaGatewayDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSMSViaGatewayDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMSViaGatewayDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSMSViaGatewayDlg, CDialog)
//{{AFX_MSG_MAP(CSMSViaGatewayDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMSViaGatewayDlg message handlers
BOOL CSMSViaGatewayDlg::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
SetCtrlValueFromReg ();
SetTimer ( 1, 5000, NULL );
AddLogTextToEditCtrl ( (CEdit*)GetDlgItem(IDC_EDIT_ReceiveSMS), NOTE_CSMSGW );
return TRUE; // return TRUE unless you set the focus to a control
}
void CSMSViaGatewayDlg::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 CSMSViaGatewayDlg::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 CSMSViaGatewayDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSMSViaGatewayDlg::SetCtrlValueFromReg()
{
SetDlgItemText ( IDC_EDIT_URL, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_URL", "61.156.3.10" ) );
SetDlgItemText ( IDC_EDIT_PORT, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_PORT", "80" ) );
SetDlgItemText ( IDC_EDIT_WebPageName_Send, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_WebPageName_Send", "/SendSms800" ) );
SetDlgItemText ( IDC_EDIT_WebPageName_Recv, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_WebPageName_Recv", "/RecvSms800" ) );
SetDlgItemText ( IDC_EDIT_CORPID, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_CORPID", "8005320623" ) );
SetDlgItemText ( IDC_EDIT_CPPW, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_CPPW", "" ) );
SetDlgItemText ( IDC_EDIT_ReceiverMobileNO, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_ReceiverMobileNO", "" ) );
SetDlgItemText ( IDC_EDIT_SMSContent, AfxGetApp()->GetProfileString ( "CtrlValue", "IDC_EDIT_SMSContent", "" ) );
}
void CSMSViaGatewayDlg::SaveCtrlValueToReg()
{
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_URL", GetDlgItemText(IDC_EDIT_URL) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_PORT", GetDlgItemText(IDC_EDIT_PORT) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_WebPageName_Send", GetDlgItemText(IDC_EDIT_WebPageName_Send) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_WebPageName_Recv", GetDlgItemText(IDC_EDIT_WebPageName_Recv) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_CORPID", GetDlgItemText(IDC_EDIT_CORPID) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_CPPW", GetDlgItemText(IDC_EDIT_CPPW) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_ReceiverMobileNO", GetDlgItemText(IDC_EDIT_ReceiverMobileNO) );
AfxGetApp()->WriteProfileString ( "CtrlValue", "IDC_EDIT_SMSContent", GetDlgItemText(IDC_EDIT_SMSContent) );
}
CString CSMSViaGatewayDlg::GetDlgItemText(UINT nID)
{
CString csText;
CWnd::GetDlgItemText ( nID, csText );
return csText;
}
void CSMSViaGatewayDlg::OnDestroy()
{
CDialog::OnDestroy();
SaveCtrlValueToReg ();
}
BOOL CSMSViaGatewayDlg::Init_SMSGW ( CSMSGW &SMSGW, BOOL bQuiet )
{
if ( !SMSGW.Init ( GetDlgItemText(IDC_EDIT_URL), GetDlgItemText(IDC_EDIT_WebPageName_Send),
GetDlgItemText(IDC_EDIT_WebPageName_Recv), atoi(GetDlgItemText(IDC_EDIT_PORT)),
GetDlgItemText(IDC_EDIT_CORPID), GetDlgItemText(IDC_EDIT_CPPW) ) )
{
if ( !bQuiet )
AfxMessageBox ( "Initialize gateway SMS module failed" );
return FALSE;
}
return TRUE;
}
void CSMSViaGatewayDlg::OnOK()
{
CSMSGW SMSGW;
if ( Init_SMSGW ( SMSGW, FALSE ) )
{
if ( SMSGW.SendSMS ( GetDlgItemText(IDC_EDIT_ReceiverMobileNO), GetDlgItemText(IDC_EDIT_SMSContent) ) )
{
AfxMessageBox ( "Send SMS successfully", MB_ICONINFORMATION );
}
else
{
AfxMessageBox ( "Send SMS successfully", MB_ICONWARNING );
}
}
}
void CSMSViaGatewayDlg::OnTimer(UINT nIDEvent)
{
if ( nIDEvent == 1 )
{
CSMSGW SMSGW;
if ( Init_SMSGW ( SMSGW, TRUE ) )
{
CStringArray StrAry_SenderMobileNO, StrAry_SMSContent, StrAry_RecvTime;
int nRet = SMSGW.ReceiveSMS ( StrAry_SenderMobileNO, StrAry_SMSContent, StrAry_RecvTime );
for ( int i=0; i<nRet; i++ )
{
CString csRecvMsgInfo = "\r\n=======================================\r\n";
csRecvMsgInfo += "MobileNO : ";
csRecvMsgInfo += StrAry_SenderMobileNO.GetAt(i);
csRecvMsgInfo += "\r\n";
csRecvMsgInfo += StrAry_SMSContent.GetAt(i);
csRecvMsgInfo += "\r\n";
csRecvMsgInfo += StrAry_RecvTime.GetAt(i);
AddLogTextToEditCtrl ( (CEdit*)GetDlgItem(IDC_EDIT_ReceiveSMS), csRecvMsgInfo );
}
}
}
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -